-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_random_nmbr.py
More file actions
24 lines (21 loc) · 1.6 KB
/
Copy pathget_random_nmbr.py
File metadata and controls
24 lines (21 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
""" The code imports the random module, which provides functions for generating random numbers.
It defines a function generate_numbers that generates count number of random integers between 0 and 100, inclusive.
The function takes two parameters:
count: The number of random numbers to generate
pseudo: A flag indicating whether or not to use a pseudo-random number generator. If pseudo is set to True, the function seeds the random number generator with the value 0.
The function uses a for loop to generate count random integers and store them in a list called numbers. The random.randint function is used to generate each random integer.
If pseudo is set to True, the random.seed function is called first to seed the random number generator with the value 0.
Finally, the generate_numbers function returns the list of generated numbers.
The code then calls the generate_numbers function twice, once with pseudo=True and once with pseudo=False, and prints the resulting lists.
If pseudo is set to True, the random number generator will always generate the same sequence of numbers, because it is seeded with the same value (0) each time the function is called.
If pseudo is set to False, the random number generator will generate a different sequence of numbers each time the function is called, because it is not seeded with a specific value. """
import random
def generate_numbers(count, pseudo=False):
numbers = []
if pseudo:
random.seed(0)
for i in range(count):
numbers.append(random.randint(0, 100))
return numbers
print(generate_numbers(5, pseudo=True))
print(generate_numbers(5, pseudo=False))