forked from codevscolor/codevscolor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_random.py
More file actions
56 lines (33 loc) · 972 Bytes
/
python_random.py
File metadata and controls
56 lines (33 loc) · 972 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# www.codevscolor.com/python-random-number-float-range/
# Print a random float
import random
print(random.random())
# Print a random float in range
import random
print(random.uniform(1,10))
# Print a random integer
import random
print(random.randrange(10))
# Print an integer number within a range
import random
print("Random number using randrange : ");
print(random.randrange(2,10))
print("Random number using randint : ");
print(random.randint(2,10))
# Print only even random number in a range
import random
print("Even Random number : ")
print(random.randrange(2,10,2))
print("Random number Divisible by 5 : ")
print(random.randrange(0,100,5))
# Print a random element in a sequence
import random
days = ["sun","mon","tue","wed","thu","fri","sat"]
print(random.choice(days))
# Shuffle a list
import random
days = ["sun","mon","tue","wed","thu","fri","sat"]
for x in range(5):
print("shuffling..")
random.shuffle(days)
print(days)