-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12_random_numbers.py
More file actions
36 lines (31 loc) · 930 Bytes
/
Copy path12_random_numbers.py
File metadata and controls
36 lines (31 loc) · 930 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
30
31
32
33
34
35
36
import random
import secrets
import numpy as np
# random.seed(10) # Makes pseudorandom behavior reproducible
print('Pseudorandom')
print(random.random()) # range: 0 - 1
print(random.uniform(1, 10)) # Still floats, includes upper bound
print(random.randint(1, 10)) # Includes upper bound
print(random.randrange(1, 10)) # Excludes upper bound
print(random.normalvariate(0, 1))
print('\n')
list1 = list('ABCDEFGHIJ')
print(list1)
print(random.choice(list1))
print(random.sample(list1, 3)) # Unique sample
print(random.choices(list1, k=3)) # Non unique sample
random.shuffle(list1) # in-place
print(list1)
print('\n')
print('Secure random')
print(secrets.randbelow(10)) # Exclusive upper bound
print(secrets.randbits(4))
print(secrets.choice(list1))
print('\n')
print('Numpy random')
# np.random.seed(10)
arr = np.random.randint(0, 10, (3, 4))
print(arr)
print('\n')
np.random.shuffle(arr)
print(arr)