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:
user_input = input("Enter a number: ")
seed = int(time.time()) + int(user_input)
random_number = (seed * 123456789) % 1000000
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!