In python, there are a set of functions that are used to manipulate random numbers.

They are generally used in games, lottery, any other application requiring random numbers. Here, we will import the file of random in order to perform its operation such as:
rd.random(), rd.randint(1,100), rd.randrange(1,100), etc.

    Algorithm:

  1. Import the file name random using python.
  2. Print the different random functions.
  3. Exit

Code:

import random as rd

print(rd.random())
#gives a random float number
print(rd.randint(1,100))
#gives a random integer between these 2 numbers

print(rd.randrange(1,100))
#gives a random integer in this range

print(rd.choice([1,2,3,4,5,6,7]))
#gives a random integer in these choices

Output:

0.3583190240354166
89
57
4

Related Posts:

[yuzo_views]











CopyRight © 2019

CopyRight © 2019