How does python use the sample () function to randomly get fragments of specified length from a specified sequence
This article is about how python uses the sample () function to randomly get fragments of a specified length from a specified sequence. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Sample (sequence,k)
Randomly get a fragment of specified length from a specified sequence
The running results are as follows:
Be careful
Random number functions are all static functions of module random.
Example
Import random# sets the random number seed random.seed (1) # generate a random number print (random.random ()) # generate a random number between 1 and 5 print (random.uniform (1mem5)) # generate a random number between 1 and 10 print (random.randint (1mem10)) # generate a random number print (random.randrange (1mem10)) list = ['hello','world','any'] incremented by 3 between 1 and 10 'way'] print (random.choice (list)) random.shuffle (list) print (random.sample (list,3)) Thank you for reading! This is the end of this article on "how python uses the sample () function to randomly get fragments of specified length from a specified sequence. I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it out for more people to see!"