RANDOM FUNCTIONS NOTES
Random numbers—a number generated by chance. i.e., randomly
When we require such numbers which are not known earlier, then in this situation we need
random numbers
Need to import random module
example: throwing dice, captcha codes, deck of cards
S.NO FUNCTION DESCRIPTION RANGE VALUES EXAMPLE
NAME
1. random () it returns a random 0.0 <= N < 1.0 >>>import random
floating point >>>print(random.random())
number 0.022353193431
*number will
always less than between 15 to 35
1.0( only the lower >>>print (random.random()*(35-
range limit 15)+15)
inclusive) 28.3071872734
2. uniform() it returns a random a <= N <= b >>>print(random.uniform(11,55))
floating point for a <= b 41.34518981317353
number N b <= N <= a for
b<a
3. randint() it returns a random a <= N <= b >>>print(random.randint(15, 35)
integer N in range 16
(a,b)
both range-limits
are inclusive
4. randrange() it returns a upper limit >>>print(random.randrange(23,47,3)
randomly selected exclusive 38
element from randrange(20)
range (start,stop, will return >>>print(random.randrange(235))
step) integers 126
it returns an between 0 to
integer between 19
upper and lower
limits
5. choice() it returns a value >>>l=[10,30,50]
from given list >>>print(random.choice(l))
[30]
6. shuffle() it will change the >>>l=[10,30,50]
order of numbers >>>print(random.shuffle(l))
in given list [30,50,10]