Reputation:
Here is my code
from random import randint
print(randint(0,9))
Now I want to know which number it will generate if run this code. What is the algorithm behind it?
Is there a way I can change it.
If that does not work, then let me ask something different
from random import randint
for i in range(10):
print(randint(0,9))
Let's take this example. This will print 10 random numbers
list[2,1,4,5,2,4,5,2,1,5]
If I know 9 numbers in the above list, is there a way to know the 10th number for that instance?
Upvotes: 2
Views: 5763
Reputation: 19133
The whole point of a random number generator is to provide random numbers. Ideally, no, there is no way to predict what's the 10th number given 9 numbers in the sequence (because, again,that's not random!)
What you can do is set the seed of the random number generator with random.seed(some_value)
. By using the same seed, the sequence of numbers generated by subsequent calls to randint() will be identical (note: identical, not predictable).
Upvotes: 1