1, taking a random number:
the random.randint (1,100) takes a random integer from 1 to 100, comprising 100.
2, random.randrange (1,100) and on a similar, but that does not include 100.
3, random.random (): generating random floating point numbers
4, random.choice ( "sdfsf2323d23") returns a random element in the string:
. 5, random.sample ( "sdfsf2323d23",. 3) returns from a given random string in 3 elements, display in list form:
6 generates a random string:
first introduced into a module:
import string
this module has the following methods:
The method of the above data sources to solve the problem of random code, and then, the generated random data to said variable name assignment,
The random.choice ()
can also be used in the form of a list of bars join method string becomes:
7, it disrupted data (shuffling):
A = [0,1,2,3,4,5,6,7,8,9]