create a random number generator in python

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.py
import random

# Generate a random number between 1 and 10
random_number = random.randint(1, 10)

print(random_number)
119 chars
7 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.py
import random

# Set the seed to 0
random.seed(0)

# Generate three random numbers
random_numbers = [random.randint(1, 10) for _ in range(3)]

print(random_numbers)
165 chars
10 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