Python Random Module: W3schools

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

w3schools.

com

  HTML CSS MORE   

Python Random Module


❮ Previous Next ❯

Python has a built-in module that you can use to make random numbers.

The random module has a set of methods:

Method Description

seed() Initialize the random number generator

getstate() Returns the current internal state of the random number generator

setstate() Restores the internal state of the random number generator

getrandbits() Returns a number representing the random bits

randrange() Returns a random number between the given range

randint() Returns a random number between the given range

choice() Returns a random element from the given sequence

choices() Returns a list with a random selection from the given sequence

shuffle() Takes a sequence and returns the sequence in a random order

sample() Returns a given sample of a sequence

random() Returns a random float number between 0 and 1


uniform() Returns a random float number between two given parameters

triangular() Returns a random float number between two given parameters, you can also
set a mode parameter to specify the midpoint between the two other
parameters

betavariate() Returns a random float number between 0 and 1 based on the Beta
distribution (used in statistics)

expovariate() Returns a random float number between 0 and 1, or between 0 and -1 if the
parameter is negative, based on the Exponential distribution (used in
statistics)

gammavariate() Returns a random float number between 0 and 1 based on the Gamma
distribution (used in statistics)

gauss() Returns a random float number between 0 and 1 based on the Gaussian
distribution (used in probability theories)

lognormvariate() Returns a random float number between 0 and 1 based on a log-normal


distribution (used in probability theories)

normalvariate() Returns a random float number between 0 and 1 based on the normal
distribution (used in probability theories)

vonmisesvariate() Returns a random float number between 0 and 1 based on the von Mises
distribution (used in directional statistics)

paretovariate() Returns a random float number between 0 and 1 based on the Pareto
distribution (used in probability theories)

weibullvariate() Returns a random float number between 0 and 1 based on the Weibull
distribution (used in statistics)

❮ Previous Next ❯

COLOR PICKER
HOW TO

Tabs
Dropdowns
Accordions
Side Navigation
Top Navigation
Modal Boxes
Progress Bars
Parallax
Login Form
HTML Includes
Google Maps
Range Sliders
Tooltips
Slideshow
Filter List
Sort List

SHARE

 

CERTIFICATES

HTML
CSS
JavaScript
SQL
Python
PHP
jQuery
Bootstrap
XML
Read More »

REPORT ERROR

PRINT PAGE

FORUM

ABOUT

Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
jQuery Tutorial
Java Tutorial
C++ Tutorial

Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
jQuery Reference
Java Reference
Angular Reference

Top Examples
HTML Examples
CSS Examples
JavaScript Examples
How To Examples
SQL Examples
Python Examples
W3.CSS Examples
Bootstrap Examples
PHP Examples
jQuery Examples
Java Examples
XML Examples

Web Certificates
HTML Certificate
CSS Certificate
JavaScript Certificate
SQL Certificate
Python Certificate
jQuery Certificate
PHP Certificate
Bootstrap Certificate
XML Certificate

Get Certified »

W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading and basic
understanding. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full
correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy
policy. Copyright 1999-2020 by Refsnes Data. All Rights Reserved.
Powered by W3.CSS.

You might also like