python3-Notes-e-001-Library-random number

Source: Internet
Author: User
Tags shuffle

Import Random# random Number Module lists = [1,2,3,4,5]DefDemo():# Generate [0, 100] random integer num = random.randint (0,) Print (num)# Generate [0, 100) random floating-point number Fnum = Random.uniform (0,) Print (Fnum)# random Get element Elem = Random.choice (lists) print (Elem)# Scrambled Order random.shuffle (lists) print (lists)DefFuns():# seed (A=none, version=2)//Initial change generator random number Random.seed () random.getstate ()# Get Generator Internal state random.setstate (Random.getstate ())# Set Generator internal state# get random number num = Random.getrandbits (8)# get an X-bit (bit) random integer# Randrange (stop)/Randrange (Start, stop[, step])//generate random integer num = random.randrange (0,100,2)# [0,100] generated random integer +2# Randint (A, b) = = Randrange (A, B + 1)//[A, b] num = Random.randint (0,1) Fnum = Random.random ()# get floating-point random number [0.0, 1.0] Fnum = Random.uniform (1,2)# Gets the floating-point random number in the specified range [1.0, 2.0]# Triangular (low, high, mode)//Get random floating-point number, lower edge (default 0), HI boundary (default 1), Mode (midpoint of default boundary) Fnum = Random.triangular (0,1,1.5)# betavariate (alpha, Beta)//beta distribution, [0.0, 1.0] Fnum = Random.betavariate (1,1)# expovariate (LAMBD)//exponential distribution, LAMBD return integer, value [0, +∞]; LANBD return negative, value [-∞, 0] fnum = random.expovariate ((Lambda arg1, Arg2:arg1 + arg2) (1,2))# The smaller the return value of LAMBD, the greater the gain# gammavariate (alpha, Beta)//Gamma Distribution Fnum = Random.gammavariate (1,1)# Gauss (Mu, sigma)//Gaussian distribution mu: mean, sigma: standard deviation fnum = Random.gauss (1,1)# lognormvariate (MU, sigma)//logarithmic normal distribution, get the average distribution of mu and standard deviation sigma; MU: Any value, sigma:>0. Fnum = Random.lognormvariate (1,1)# normalvariate (MU, sigma)//Normal distribution, mu is mean, sigma is standard deviation fnum = Random.normalvariate (1, 1) # vonmisesvariate (Mu, kappa)/ /Vom Mises distribution of random numbers. MU: Average angle (radians [0, 2*pi]), Kappa: concentration degree >=0 fnum = random.vonmisesvariate (1, 1) # paretovariate (Alpha)//Pareto distribution, alpha: Shape Fnum = random.paretovariate (1) # weibullvariate (alpha, Beta)//Weber distribution, Alpha: Zoom, Beta: shape fnum = random . Weibullvariate (1, 1) Elem = Random.choice (lists) # the random element in a non-empty sequence, the sequence is empty throw indexerror Elems = random.sample (lists, 3) # randomly get 3 elements from the list, range > list size, throw valueerror # Shuffle random.shuffle (lists) # scrambled sequence             

Python3-notes-e-001-Library-random number randomly

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.