Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

Python Random Module-W3Schools

The Python Random Module provides various methods for generating random numbers and sequences. Key methods include seed(), randint(), choice(), shuffle(), and several statistical distributions like normalvariate() and gammavariate(). This module is essential for tasks requiring randomness in Python programming.

Uploaded by

recemo4098
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Python Random Module-W3Schools

The Python Random Module provides various methods for generating random numbers and sequences. Key methods include seed(), randint(), choice(), shuffle(), and several statistical distributions like normalvariate() and gammavariate(). This module is essential for tasks requiring randomness in Python programming.

Uploaded by

recemo4098
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

5/22/25, 9:38 AM Python Random Module

 Tutorials  Exercises  Services   Get Certified Sign In

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

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

https://www.w3schools.com/python/module_random.asp 1/5
5/22/25, 9:38 AM Python Random Module

uniform()
Tutorials  Returns a random float number between
Exercises  Services   two given parametersSign In
Get Certified
triangular() Returns a random float number between two given parameters,
HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
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 based on the Exponential


distribution (used in statistics)

gammavariate() Returns a random float number based on the Gamma distribution


(used in statistics)

gauss() Returns a random float number based on the Gaussian


distribution (used in probability theories)

lognormvariate() Returns a random float number based on a log-normal


distribution (used in probability theories)

normalvariate() Returns a random float number based on the normal distribution


(used in probability theories)

vonmisesvariate() Returns a random float number based on the von Mises


distribution (used in directional statistics)

paretovariate() Returns a random float number based on the Pareto distribution


(used in probability theories)

weibullvariate() Returns a random float number based on the Weibull distribution


(used in statistics)

❮ Previous Next ❯

Track your progress - it's free! Sign Up Log in

https://www.w3schools.com/python/module_random.asp 2/5
5/22/25, 9:38 AM Python Random Module

 Tutorials  Exercises  Services   Get Certified Sign In

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

COLOR PICKER



https://www.w3schools.com/python/module_random.asp 3/5
5/22/25, 9:38 AM Python Random Module

 Tutorials  Exercises  Services   Get Certified Sign In

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

 PLUS SPACES

GET CERTIFIED FOR TEACHERS

FOR BUSINESS CONTACT US

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

Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
https://www.w3schools.com/python/module_random.asp 4/5
5/22/25, 9:38 AM Python Random Module
W3.CSS Reference

 Tutorials  Bootstrap Reference


Exercises 
PHP Reference
Services   Get Certified Sign In
HTML Colors
HTML
 CSS Java
JAVASCRIPT ReferenceSQL PYTHON JAVA PHP HOW TO W3.CSS C
Angular Reference
jQuery Reference

Top Examples Get Certified


HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
W3.CSS Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate

    

FORUM ABOUT ACADEMY


W3Schools is optimized for learning and training. Examples might be simplified to improve
reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot
warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted our terms of use,
cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

https://www.w3schools.com/python/module_random.asp 5/5

You might also like