pyhton random module

Python generates a random number, a random string


#
/ usr / bin / Python! # - * - Coding: UTF-. 8 - * - Import Random Import String # random integer: Print the random.randint (1,50 ) # randomly selected to 0 100 is an even number: Print random.randrange (0, 101, 2 ) # random floating point: Print random.random () Print random.uniform (. 1, 10 ) # random character: Print the random.choice ( ' ABCDEFGHIJKLMNOPQRSTUVWXYZ @ #! $% ^ & * () ' ) # plurality of characters specified number of random characters generated: Print random.sample ( 'zyxwvutsrqponmlkjihgfedcba ' ,. 5 ) # generates a specified number of characters from random-zA-Z0-9 A: ran_str = ' ' .join (random.sample (string.ascii_letters + string.digits,. 8 )) Print ran_str # plurality of characters selecting a specified number of characters new string: Print '' .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 strings: Print The random.choice ([ ' scissors ' , ' rock ' , ' cloth ' ]) # disrupted sort items = [1, 2,. 3,. 4,. 5,. 6,. 7,. 8,. 9 , 0] Print random.shuffle (items)

 

 

Guess you like

Origin www.cnblogs.com/QQmini/p/11415376.html