The random function describes the following methods of the random module:
betavariate
get a random floating-point number before range (0,1)
method: Random.betavariate (Alpha,beta) return value: Float For example: print (Random.betavariate (3,4)) > >> 0.4179835782470355# This method requires two parameters that are greater than 0 to execute, that is, two parameter types need to be numeric types.
choice
Random get elements of a non-empty sequence
method: Random.choice (SEQ) return Value: Object For example: print (Random.choice (' abc ')) >>> a# The parameters passed in need to be a sequence or an iterative object
Expovariate
Random acquisition of 1/n averages to infinity floating-point numbers
方法:random.expovariate(num)返回值:float例如:print(random.expovariate(100)) >>> 0.002053324332834578#由于传入的参数是作为1的除数,因此不能是零,可以是正负数。
- Gammavariate
- Gauss
- GetState
- Lognormvariate
- Normalvariate
- Paretovariate
Random.randint
Randomly gets an integer from the specified integer range
方法:random.randint(start,stop)返回值:int例如:print(random.randint(1,2)) >>> 2#上述取值包含结束的整数
randrange
randomly gets an integer from the specified integer range
method: Random.randrange (Start,stop=none,step=1) return value: Int for example: print (Random.randrange ( -2,2 ) >>> # This method, when the starting value is positive, you can not specify the end value, the starting value is negative, you must specify the end value, or the program error, the method can also specify the step size.
Sample
Gets the specified number of random objects from the specified range and returns them as a list
方法:random.sample(seq,num)返回值:object例如:print(random.sample(‘abc‘,2)) >>> [‘b‘,‘a‘]#上述的num参数必须小于等于seq序列的长度,否则程序报错
- Seed
- SetState
- Shuffle
- Triangular
Uniform
Gets a random floating-point number from the specified range
方法:random.uniform(start,stop)返回值:float例如:print(random.uniform(-1,1.1)) >>> -0.5195993353320494#该方法传入的指定范围可以是浮点数,也可以是整数
- Vonmisesvariate
- Weibullvariate
Random
Get a random floating-point number in the 0-1 range
方法:random.random()返回值:float例如:print(random.random()) >>> 0.9014274576114836#该方法不用穿参数。
Description of the function of the random module in Python