-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpseudo_random_numbers.py
50 lines (36 loc) · 1.38 KB
/
pseudo_random_numbers.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
#using random module
# random.randint() , random.randrange() , random.random() , random.choice() , random.uniform()
import random
print(random.randint(10,100))
#generates random integers between the arguments provided to it
print(random.randrange(10))
print(random.randrange(10,20))
print(random.randrange(100,200,3,))
#first argument is the 'start'
#second argument is the 'stop'
#third argument is the 'step'
for i in range(1,6):
print(random.randint(10,100))
#prints 5 random number between the arguments
#arguments are the values that we put in the parentheses of a function
print(random.random())
#prints random floating number smaller than 1
''' Functions used to print "INTEGERS"
1.syntax of randrange function
random.randrange(start,stop,step)
2.syntax of randint function
random.randint(start, stop)
'''
print(random.choice("NEELPANDEY"))
#gives any random string literal from the given input
#can be used for string , lists , arrays etc.
print(random.uniform(10,20))
#gives any random floating number between the two arguments
#generate 10 random numbers between 1 to 100 and sort them in ascending order
l=[]
for i in range(1,11):
l.append(random.randrange(1,100))
l1=sorted(l)
print(l1)
'''generate 10 random numbers between 1 to 100 and sort them in ascending order
and search if 50 is in the array using binary search'''