To create a random number generator in Python, you can use the built-in random
module.
To generate a random integer between two values, you can use the randint
function. Here's an example:
main.py119 chars7 lines
You can also set a seed for the random number generator using the seed
function. This is useful if you want to generate the same sequence of random numbers every time you run your program. Here's an example:
main.py165 chars10 lines
This will output [6, 6, 4]
, since setting the seed to 0 ensures that the same sequence of random numbers is generated every time the program is run.
gistlibby LogSnag