+ 3

How do I generate a random integer?

Please answear in .py code format Thanks guys!

19th Jan 2017, 7:09 AM
Will_De
Will_De - avatar
4 Answers
+ 10
It generates namber of [2, 3, 4, 5, 6, 7, 8]
19th Jan 2017, 7:23 AM
Sergey
+ 4
from random import randint print(randint(2,9)) where (2,9) is the range from you want to get a random int.
19th Jan 2017, 7:15 AM
Álvaro
+ 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.
19th Jan 2017, 10:14 AM
Álvaro
+ 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 ^^
19th Jan 2017, 9:48 AM
visph
visph - avatar