Python Random Module:
We can use the PyCharm code editor for this example. If you do not know about it then follow this link- How to install PyCharm for Python and create a program in it. |
(1) The random module provides tools for making random selections. Random numbers are used for games, simulations, testing, security, and privacy applications.
(2) randint()– The randint() function in the program takes two integer arguments and returns a random integer between those two integers (including the integers). The numbers generated by the randint() function are not truly random. They are produced from a pseudorandom number generator algorithm, which takes an initial number and produces other numbers based on a formula.

(3) randrange()– The randrange() function is used to select a pseudorandom int from a given range. It can be used with one, two, or three parameters to specify a range exactly as with the range function. For example, randrange (1, 4) returns some number from the range [1,2,3], and randrange (2,12,2) returns a multiple of 2 between 2 and 10, inclusive. Note- ranges go up to, but do not include, the stopping value.


(4) choice()– The choice() function will return a randomly selected item from the list.

(5) shuffle()– The shuffle() function will reorder the items in a list. This function modifies the list in place, rather than returning a new list.

(6) random()– The random() function returns a random float number between 0 and 1.

(7) uniform()– The uniform() function returns a random float number between two given parameters.

Comments (No)