Use random module Python modules,

Random Import 
Import String

# random integer:
Print (the random.randint (1,50))

# randomly selected the even-numbered 0-100:
Print (random.randrange (0, 101, 2))

# random floating point:
Print (Random .random ())
Print (random.uniform (. 1, 10))

# random characters:
Print (the random.choice ( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ @ # $% ^ & * ()!'))

# plurality of specified number of characters generated random character:
Print (random.sample ( 'zyxwvutsrqponmlkjihgfedcba',. 5))

# specified number generated from a-zA-Z0-9 random character:
ran_str = '' .join (random.sample (+ string.digits string.ascii_letters ,. 8))
Print (ran_str)

selected specified number of characters # plurality of character strings in the new composition:
Print ( ''. the Join (random.sample ([ 'Z', 'Y', 'X', 'W' , 'v', 'u' , 't', 's',' r ',' q ',' p ',' o ','n ',' m ',' l ',' k ',' j ',' i ',' h ',' g ',' f ',' e ',' d ',' c ',' b ' , 'A'],. 5)))

# randomly selected string:
print (random.choice ([ 'scissors', 'rock', 'cloth']))

# disrupted sort
items = [. 1, 2,. 3,. 4,. 5,. 6,. 7,. 8,. 9, 0]
Random. shuffle (items)
Print (items)
# Print (random.shuffle (items)) can not be directly printed items, must be written separately

Guess you like

Origin www.cnblogs.com/zhlan/p/11924270.html
Recommended