Quantcast
Channel: Python Archives - Tutorials Made
Viewing all articles
Browse latest Browse all 24

Generate random numbers in Python without using Random module

$
0
0

Generating random numbers in Python without using the built-in random the module can be challenging, as the process of generating truly random numbers requires specialized hardware or algorithms. However, one approach could be to use some other source of randomnesses, such as the current time or the user’s input, to simulate randomness.

Here’s an example program that generates a “random” number based on the user’s input:

import time

user_input = input("Enter a number: ")
seed = int(time.time()) + int(user_input)
random_number = (seed * 123456789) % 1000000
print(random_number)

The above Python program prompts the user to enter a number, which is used as a “seed” for the pseudo-random number generator. The program then generates a “random” number by multiplying the seed by a large prime number and taking the remainder when divided by a large integer (in this case, 1,000,000). While this method is not truly random, it can produce results that are unpredictable and appear to be random.

Note: This approach should not be used for security-critical applications, as it is relatively easy to predict the “random” numbers generated using this method.

Hope this program is helpful for you. Keep reading!

The post Generate random numbers in Python without using Random module appeared first on Tutorials Made.


Viewing all articles
Browse latest Browse all 24

Latest Images

Trending Articles



Latest Images