-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRandom_module part 3.py
62 lines (53 loc) · 1.34 KB
/
Random_module part 3.py
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
57
58
59
60
61
62
#;==========================================
#; Title: Python Random module part 3
#; Author: @AyemunHossain
#;==========================================
import random as r
#whole random module is controled by seed value
r.seed(0)
print(r.randint(0,500))
r.seed(0)
print(r.randint(0,500))
r.seed()
###let's shuffling a string
name="ashik"
l_n=list(name)
r.shuffle(l_n)
name=''.join(l_n)
print(name)
#shuffle second time
l_n=list(name)
r.shuffle(l_n)
name=''.join(l_n)
print(name)
#let's control shuffling by seed
name="ashik"
l_n=list(name)
r.seed(0)
r.shuffle(l_n)
name=''.join(l_n)
print(name)
name="ashik"
l_n=list(name)
r.seed(0)
r.shuffle(l_n)
name=''.join(l_n)
print(name)
r.seed()
#note: you can actually do the shuffle with the help of sample
lis=[1,2,3,4,5]
r.seed() #when you need to clear seed value from others then just type it :
look_like_shuffle=r.sample(lis,len(lis))
print(look_like_shuffle)
#shuffle two python list at once with same order :
empName = ['Jhon', 'Emma', 'Kelly', 'Jason']
empSalary = [7000, 6500, 9000, 10000]
suf_both=list(zip(empName,empSalary))
r.shuffle(suf_both)
s_name,s_salary=zip(*suf_both)
s_name,s_salary=list(s_name),list(s_salary)
print(s_name,s_salary)
#generate random float number with nth of precision
print(round(r.uniform(0.1,5.0),5))
print(round(r.uniform(0.1,5.0),3))
print(round(r.uniform(0.1,5.0),9))