A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/python/python_random_module.htm below:

Python - Random Module

Python - Random Module

The random module is a standard library module that offers functions for various operations such as random number generation, shuffling sequences, and making random selections. In this module, we will examine the features of the Python random module and provide real-world examples to demonstrate how to use it.

While developing applications, the utilization of python "random" module becomes vital for tasks such as statistical analysis, games, securing cryptographic keys for sensitive data etc. Let us navigate through some of the spectrum of methods with different types of data.

We do know that random module provides various functions for generating random numbers, however, what may not be apparent is that these functions are bound methods of a hidden instance of the random.Random class. This means, python creates an instance of the Random class and binds the functions to that instance.
Python random.Random class

The Random class executes the default pseudo-random number generator which is used by the random module. The constructor random.Random([seed]) is responsible for creating an instance of the Random class, further allowing for the initialization of a random number generator.

The seed determines the starting point for generating random numbers. Functions such as getstate() and setstate() allows us to access and update the internal state of the generator, which enables the preservation and restoration of the sequences.

Python random.SystemRandom Class

Random module not only provides Random class for random number generation, it also provides the SystemRandom class which is designed to use the system-provided source to generate random numbers. This class uses os.urandom() function which generates cryptographically secured bytes and random numbers.

Let us see various functions in random module.

Functions for Integers

Following are the functions specifically designed for working with integers −

Functions for Sequences

Following are the functions specifically designed for working with sequences −

Functions for Distributions

Following are the functions specifically designed for working with distributions −

Sr.No. Function & Description 1

Python random.binomialvariate(n,p) function

This function returns an integer value representing the no:of successes observed for n trails with a probability p.

2

Python random.uniform(a, b) function

This function returns a random float value between a, b (inclusive).

3

Python random.triangular(a,b,mode) function

This function returns a float value between a,b both inclusive with a specified mode between the bounds.

4

Python random.betavariate() function

This function returns a random variate which follows beta distribution.

5

Python random.expovariate(lambd=) function

If the parameter lambd is positive, the function returns a value ranges from 0 to positive infinity. If lambd is negative, it returns a value between negative infinity and 0.

6

Python random.gammavariate(alpha,beta) function

This function returns a random variate which follows gamma distribution with shape parameter alpha and scale parameter beta.

7

Python random.gauss(mu,std) function

This function returns a random variate which follows gaussian distribution with mean "mu" and standard deviation "std".

8

Python random.lognormvariate(mu,std) function

This function returns a random variate which follows log norm distribution with mean "mu" and standard deviation "std".

9

Python random.normalvariate(mu,std) function

This function returns a random variate which follows normal distribution with mean "mu" and standard deviation "std".

10

Python random.vonmisesvariate(mu,kappa) function

This function returns a random variate which follows von Mises distribution with mean angle mu and concentration parameter which measures the dispersion of the distribution.

11

Python random.paretovariate(alpha) function

This function returns a random variate which follows pareto distribution with shape parameter alpha.

12

Python random.weibullvariate(alpha, beta) function

This function returns a random variate which follows weibull distribution with shape parameter alpha and scale parameter beta.

Functions for Bytes

Following are the functions specifically designed for working with bytes −

Functions for Alternative Generators

Following are the functions specifically designed for alternative generators −


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4