Hello! I am not sure how I would write in Python code that can generate random numbers without using the built-in import random function. Is this possible? So far, my code is: import random # Define 20 random numbers between 1-100 numbers_random = [random.randint(1, 100) for _ in range(20)] # Find the lowest number of the random numbers numbers_lowest = min(numbers_random) # Find the highest number of the random numbers numbers_highest = max(numbers_random) # Define the total of all numbers numbers_total = sum(numbers_random) # Define the average of all numbers numbers_average = total / len(numbers_random) # Show all data print("Twenty random numbers:", numbers_random) print("Lowest number:", numbers_lowest) print("Highest number:", numbers_highest) print("Total of the numbers:", numbers_total) print("Average of the numbers:", numbers_average) What I am doing with this Python code is creating 20 random numbers that are between 1-100 and showing the lowest number, highest number, the total and the averages whilst using the built-in list functions. I just want to challenge myself by not using the import random function at the top. Is there a way to do that?
Hello! I am not sure how I would write in Python code that can generate random numbers without using the built-in import random function. Is this possible?
So far, my code is:
import random
# Define 20 random numbers between 1-100
numbers_random = [random.randint(1, 100) for _ in range(20)]
# Find the lowest number of the random numbers
numbers_lowest = min(numbers_random)
# Find the highest number of the random numbers
numbers_highest = max(numbers_random)
# Define the total of all numbers
numbers_total = sum(numbers_random)
# Define the average of all numbers
numbers_average = total / len(numbers_random)
# Show all data
print("Twenty random numbers:", numbers_random)
print("Lowest number:", numbers_lowest)
print("Highest number:", numbers_highest)
print("Total of the numbers:", numbers_total)
print("Average of the numbers:", numbers_average)
What I am doing with this Python code is creating 20 random numbers that are between 1-100 and showing the lowest number, highest number, the total and the averages whilst using the built-in list functions. I just want to challenge myself by not using the import random function at the top. Is there a way to do that?
In the provided scenario,The challenge is to generate random numbers in Python without using the built-in random
module. Instead, we'll create a custom pseudo-random number generator to mimic the functionality of the random
module. This involves designing a basic algorithm for generating random-like numbers. Keep in mind that these numbers won't be truly random, but they can simulate randomness effectively for educational purposes. The custom generator will be used to create 20 pseudo-random numbers within a specified range. The code will then calculate statistics such as the lowest number, highest number, total, and average of the generated values, much like what the random
module enables. This exercise offers insight into the underlying mechanisms of random number generation and provides a valuable learning experience.
Step by step
Solved in 4 steps with 1 images