The method of random function python

 

Python standard library of random function, you can generate a random floating-point, integer , string , and even help you choose a random list order

A column element, like a set of data upset.

  random some of the important functions of usage:

1), random () returns 0 <= n <n random real number between. 1;
2), Choice (seq) returns a random element from the sequence of seq;
. 3), getrandbits (n) Returns the n as a long form random bits;
. 4), shuffle (seq [, random]) specify the place seq.;
. 5), Sample (seq, n) and randomly selecting n sequences from the individual elements in seq;

 Details:

random.random () function in this module is the most common method, and it generates a random floating point number in the range between 0.0 and 1.0.

random.uniform () just to make up for the lack of the above functions, it can set the range of floating-point numbers, a is the upper limit, a lower limit.

the random.randint () generated randomly an integer int type, this range can be specified integer, the same upper and lower limits, python random.randint.

The random.choice () may be any sequence from such list file, select a random element returns, may be used for strings, lists, tuples like.

random.shuffle () if you want a sequence of elements, random upset, then you can use this function method.

random.sample () can be randomly taken from the specified segment length specified sequence, it is not modified in situ.

Guess you like

Origin www.cnblogs.com/sunflowers-lanqijiu/p/11961342.html
Recommended