Random Number Functions in Python

PythonServer Side ProgrammingProgramming

Random numbers are used for games, simulations, testing, security, and privacy applications. Python includes following functions that are commonly used.

Sr.NoFunction & Description
1choice(seq)
A random item from a list, tuple, or string.
2randrange ([start,] stop [,step])
A randomly selected element from range(start, stop, step)
3random()
A random float r, such that 0 is less than or equal to r and r is less than 1
4seed([x])
Sets the integer starting value used in generating random numbers. Call this function before calling any other random module function. Returns None.
5shuffle(lst)
Randomizes the items of a list in place. Returns None.
6uniform(x, y)
A random float r, such that x is less than or equal to r and r is less than y
raja
Published on 28-Jan-2020 11:43:01
Advertisements