Skip to main content

Python Random Module

 

Python Random Module


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

The random module has a set of methods:

MethodDescription
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 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)

Comments

Popular posts from this blog

Python Introduction

  Python  Introduction What is Python? Python is a popular programming language. It was created by Guido van Rossum, and released in 1991. It is used for: web development (server-side), software development, mathematics, system scripting. What can Python do? Python can be used on a server to create web applications. Python can be used alongside software to create workflows. Python can connect to database systems. It can also read and modify files. Python can be used to handle big data and perform complex mathematics. Python can be used for rapid prototyping, or for production-ready software development. Why Python? Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc). Python has a simple syntax similar to the English language. Python has syntax that allows developers to write programs with fewer lines than some other programming languages. Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means that p...

LIST OF TOPICS YOU WILL BE LEARN THIS WHOLE SERIES

Python  Introduction    Python  Getting Started Python  Variables Python  Comments Python Try Except Python Data Types Python Casting Python Strings Python Operators Python Lists Python Tuples Python Sets Python Dictionaries Python Arrays Python PIP Python Booleans Python If  Else Python Loops Python Functions Python Lambda Function Python Modules Python Random Module Python cmath Module Python Math Module Python Classes and Objects Python Inheritance PYTHON FILE I/O                Video Contain 1. Telusko 2. CodeWithHarry For Certification Course 01. Udemy1 02. Udemy2                                                                                                     ...

Python Getting Started

  Python  Getting Started Python Install Many PCs and Macs will have python already installed. To check if you have python installed on a Windows PC, search in the start bar for Python or run the following on the Command Line (cmd.exe): C:\Users\ Your Name >python --version To check if you have python installed on a Linux or Mac, then on linux open the command line or on Mac open the Terminal and type: python --version If you find that you do not have python installed on your computer, then you can download it for free from the following website:  https://www.python.org/ Python Quickstart Python is an interpreted programming language, this means that as a developer you write Python (.py) files in a text editor and then put those files into the python interpreter to be executed. The way to run a python file is like this on the command line: C:\Users\ Your Name >python helloworld.py Where "helloworld.py" is the name of your python file. Let's write our first Python fi...