I developed a simple application that generates a series of test data, and I built it to be able to be repeatable using random seed. I noticed the following and wanted to find out why this is happening:
>>> random.seed(1) >>> [random.randint(0,10) for _ in range(0,10)] [2, 9, 1, 4, 1, 7, 7, 7, 10, 6] >>> random.seed(1) >>> random.random() 0.13436424411240122 >>> [random.randint(0,10) for _ in range(0,10)] [1, 4, 1, 7, 7, 7, 10, 6, 3, 1]
Notice how one call to random () uses two values ββfor randint (). I suppose this has something to do with the amount of random information needed to create a float versus int in a given range, but is there a way to keep track of βhow many random values ββhave been used so far?β, I.e. how far in the sequence of semi-random values is the system equal to?
I ended up writing my own function, always using a single call to random.random () in my logic. So I do not ask permission, just a little background / explanation.
source share