In Python, we can use the randint module to generate a random integer. Please note that the random integer thus generated is a pseudo-random number and not a truly random number (What is the difference between a true random number and a pseudo-random number?).
A pseudo-random number generator is an algorithm that generates a sequence of random numbers. These random numbers have properties closer to random numbers generated by a true random number generator, but they are not truly random.
We can use the seed module to initialize the pseudo-random number generator. The seed() function takes an integer as input. If no input is given, then it uses the current system time to initialize the pseudo-random number generator. Please note that the generated random integer depends on this seed value. If we use the same seed value twice, then the same sequence of random integers will be generated both times.
from random import randint from random import seed seed(1) number = randint(1, 100) print(number)
The above piece of Python code generates a random integer between 1 to 100. Please note that the function randint(a, b) takes two integers a and b as input and generates a random integer N as output. Here, a ≤ N ≤ b. In other words, the function randint(a, b) generates a random integer in the range [a, b].






0 Comments