Search code examples
pythonrandomprobability

randomly pick an element from a list in python using pseudo random generator which should happen 50 percent of time


I have a list which has certain elements.For example event=["head","tail"].Each element should be picked randomly using pseudo random generator.This random event should occur roughly 50 percent of time.Use some sort of pseudo random number generator, but make this in a way that we can repeat the test or the sequence that way if something in the test fails, we can repeat what happened.This should be implemented in python


Solution

  • import random as rnd
    coin=["h","t"]
    seed=10
    rnd.seed(seed)
    
    for i in range(100):
        print coin[rnd.randint(0,1)]
    

    Is this what you want? Please be more specific in future questions