-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomModule.py
More file actions
26 lines (16 loc) · 822 Bytes
/
RandomModule.py
File metadata and controls
26 lines (16 loc) · 822 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
# Random Module helps you pick a random number from the range you give it.
import random
print(random.randrange(0, 99)) #picks from the randome range of 0 to 99
x = range(1,999)
print(random.choice(x)) #picks fromt he range you hvae given it the range acts as sequence
print(random.random()) #picks a random float from 0.234, 0.897
print(random.randint(1, 10)) #picks a random integer between the sequence
fruits = ['apple', 'banana', 'cherry']
print(random.choice(fruits)) #similar to range, picks a value out of list
nums = [1, 2, 3]
print(random.choices(nums, k=5))# same as above but this one actually gives 5 random values beacuase of 'k'
nums = [1, 2, 3, 4]
print(random.sample(nums, 2))# picks unique elements unlike above one
nums = [1, 2, 3, 4]
random.shuffle(nums)#used to shuffle the list
print(nums)