# Difference between revisions of "Random module"

(Created page with 'The '''random module''' is used to generate pseudo-random numbers in Python. ==Useful Functions== The following are functions in the random module, see t…') |
m (typo in spelling "them" lol) |
||

Line 2: | Line 2: | ||

==Useful Functions== | ==Useful Functions== | ||

− | The following are functions in the random module, see the page on [[module (Python)|modules]] for directions on how to import | + | The following are functions in the random module, see the page on [[module (Python)|modules]] for directions on how to import them into your program. |

*<tt>random.'''random'''()</tt> returns a random [[floating point number]] between 0.0 and 1.0. | *<tt>random.'''random'''()</tt> returns a random [[floating point number]] between 0.0 and 1.0. | ||

*<tt>random.'''randint'''(a,b)</tt> returns a random [[integer]] between a and b, inclusive. | *<tt>random.'''randint'''(a,b)</tt> returns a random [[integer]] between a and b, inclusive. |

## Latest revision as of 12:55, 30 June 2020

The **random module** is used to generate pseudo-random numbers in Python.

## Useful Functions

The following are functions in the random module, see the page on modules for directions on how to import them into your program.

`random.`returns a random floating point number between 0.0 and 1.0.**random**()`random.`returns a random integer between a and b, inclusive.**randint**(a,b)`random.`returns a random floating point number between a and b.**uniform**(a,b)`random.`returns a random element of sequence**choice**(s)`s`. For example,`random.choice([1,3,7])`will return either 1, 3, or 7.`random.`shuffles sequence**shuffle**(s)`s`in place. Hence, the original s is changed and nothing is returned. If you want to preserve the original order also you need to copy the list first (`myListCopy = myList[:]`would work).