Random Number Generation in Python
Following python program will generate 100 random numbers between 1 to 100.
import random
# Define a blank list to store the random numbers
random_numbers = []
# Loop 100 times to generate 100 random numbers
for _ in range(100):
# Generate a random integer between 1 and 100 (inclusive)
number = random.randint(1, 100)
# Append the random number to the list
random_numbers.append(number)
# Print the list of random numbers
print("Generated 100 random numbers in range 1 to 100:")
print(random_numbers)
Output
Generated 100 random numbers in range 1 to 100:
[31, 48, 64, 37, 69, 53, 75, 24, 34, 19, 5, 2, 44, 12, 51, 96, 49, 92, 54, 99, 78, 68, 87, 74, 92, 53, 68, 41, 76, 13, 59, 89, 52, 99, 17, 41, 37, 43, 47, 32, 13, 10, 91, 87, 46, 3, 29, 46, 11, 71, 74, 26, 21, 63, 67, 80, 10, 33, 4, 4, 30, 89, 63, 93, 90, 24, 2, 46, 73, 91, 88, 94, 5, 93, 18, 5, 31, 93, 66, 54, 28, 8, 11, 39, 17, 96, 91, 60, 38, 4, 77, 98, 7, 45, 48, 64, 51, 40, 38, 34]
* * *
No comments:
Post a Comment