+ 3
How do I generate a random integer?
Please answear in .py code format Thanks guys!
4 Antworten
+ 10
It generates namber of [2, 3, 4, 5, 6, 7, 8]
+ 4
from random import randint
print(randint(2,9))
where (2,9) is the range from you want to get a random int.
+ 4
@visph: you can actually call the random.seed() function:
import random
random.seed()
print(random.randint(2,9))
#or whichever limits you want
This returns a different value every time you run it on the code playground.
+ 3
@Sergey:
You confuse with the range() function ^^
For use randint() function you must import module 'random'... and know that only generate PSEUDO-random numbers: on code playground interpreter, the value is the same at each run ( for sames parameters, obviously ). Try to search, there's probably a function for resetting more or less the generator base ^^