-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathrandom_ints.py
More file actions
29 lines (26 loc) · 761 Bytes
/
Copy pathrandom_ints.py
File metadata and controls
29 lines (26 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import random
def random_ints():
# initialize an empty list to store the numbers
numbers = []
# initialize a variable to store the current number
number = 0
# loop until the number is 6
while number != 6:
# generate a random number in the range [1,10]
number = int(random.random()*10) + 1
# append the number to the list
numbers.append(number)
return numbers
def test():
N = 10000
total_length = 0
for i in range(N):
l = random_ints()
assert not 0 in l
assert not 11 in l
assert l[-1] == 6
total_length += len(l)
assert abs(total_length / N - 10) < 1 # checks that the length of the random strings are reasonable.
print("Success!")
if __name__ == "__main__":
test()