I. Introduction to the Random module
The random function in the Python standard library can generate randomly floating-point numbers, integers, strings, and even help you randomly select an element in a list sequence, disrupting a set of data, and so on.
Second, the random module important function
1) and random () returns the random real number n between 0<=n<1;
2), choice (seq) returns a random element from the sequence seq;
3), Getrandbits (n) returns n random bits in the form of a long integer;
4), Shuffle (seq[, random]) specify the SEQ sequence in situ;
5), sample (SEQ, n) select n Random and independent elements from the sequence seq;
Iii. description of the Random module method
The random.random () function is the most commonly used method in this module, and it generates a random floating-point number, ranging between 0.0~1.0.
random.uniform () just makes up for the insufficiency of the above function, it can set the range of floating-point number, one is the upper limit, one is the lower limit.
random.randint () randomly gives an integer int type, which can specify the range of this integer, as well as upper and lower values, Python random.randint.
Random.choice () can be returned from any sequence, such as a list, by selecting a random element, which can be used for strings, lists, tuples, and so on.
random.shuffle () This function method can be used if you want to shuffle an element in a sequence randomly.
random.sample () can randomly intercept fragments of a specified length from a specified sequence, without modifying them in situ.
Python random Module sample, Randint, shuffle, Choice stochastic functions