Python Standard library-random Learning

Source: Internet
Author: User

Reference: Python 2.7.7 Documentation
Reference tool: http://translate.google.cn/
Random Module Learning

First, bookkeeping functions (barely read)
Random.seed ([x]) Initialize the basic random number generator
Random.getstate () Return an object capturing the current internal state of the generator
Random.setstate (state)
Random.jumpahead (N)
Random.getrandbits (k) Returns a python long int with k random bits.
Try it, a long type of 2bit (random value 0-3)
>>> print random.getrandbits (2)
0
Try it, a long type of 2bit (random value 0-3)

Second, ★functions for integers (integer)
Random.randrange (STOP)
Random.randrange (Start, stop[, step])
Random.randint (A, B)

Three, ★functions for sequences (sequence)
Random.choice (SEQ) returns any element of a non-empty sequence
>>> Random.choice ([1, ' Hello ', ' world ')
' Hello '
Random.shuffle (x[, random]) randomly sorts all elements of a sequence
Random.sample (population, k) gets a random fragment of the specified length from the specified sequence. The sample function does not modify the original sequence.

Iv. OMG my probability theory has been returned to the teacher, so many distribution ╮(╯▽╰)╭
★random.random () returns a random floating-point number in [0.0, 1.0].
★random.uniform (A, B) returns the random floating-point number in [A, b]
Random.triangular (low=0.0, high=1.0, Mode=none)
Random.betavariate (alpha, beta) Beta distribution
Random.expovariate (LAMBD) Index distribution
Random.gammavariate (alpha, beta) gamma distribution
Random.gauss (Mu, sigma) Gaussian distribution
Random.lognormvariate (Mu, sigma) Log normal distribution
Random.normalvariate (Mu, sigma) normal distribution normal distribution
Random.vonmisesvariate (Mu, kappa)
Random.paretovariate (Alpha) Pareto distribution
Random.weibullvariate (alpha, beta) Weibull distribution

Python Standard library-random Learning

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.