In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "analyzing Python random functions". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Import module:
Import random
1. Random.choice (list / tuple / string), pick an element randomly in the list or tuple, and randomly pick a character if it is a string
Num1 = random.choice (['hello',True,1, [1mem4je 5]]) print (num1)
Output (the result of each output may not be the same):
one
2. Random.randrange ([start,end), step): returns a random number from [start,end) with a step size of step
If start does not write, the default is 0
Do not write multiple step. Default is 1.
But end must have num2 =
Random.randrange (100) print (num2) # head-to-tail num3 = random.randrange (80Power100) print (num3) # take a random number print of 1 to 6 (random.randrange (1) 7)
Output (the result of each output may not be the same):
eighty-three
eighty-four
six
3. Random.random (): returns a random number of [0Power1). The result is a floating point number
A: there are no answers to problems encountered in study. The editor has created a Python learning exchange group: 531509025 look for like-minded partners to help each other, and there are also good video learning tutorials and PDF e-books in the group! Num4 = random.random () print (num4)
Output (the result of each output may not be the same):
0.8073295394931393
4. Random.shuffle (list): sorts all the elements in the sequence randomly, directly manipulates the sequence [sequence changes], and no value is returned.
List1 = [1, list1, 3, 5, 6, 7] random.shuffle (list1) print (random.shuffle (list1)) # returns Noneprint (list1)
Output (the result of each output may not be the same):
None
[1, 7, 5, 6, 3, 2]
5. Random.uniform (m _ # n): randomly generate a floating-point number [m ~ m _ n]
Print (random.uniform (5, 4))
Output (the result of each output may not be the same):
4.697767338612918
6. Random.randint (mQuery n)
Randomly generate an integer of [m _ m _ n]
Print (random.randint (- 1pr 4))
Output (the result of each output may not be the same):
0
This is the end of "analyzing Python Random functions". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.