当前位置:   article > 正文

python中random的使用_python的random调用

python的random调用
  1. >>> random.random() # Random float x, 0.0 <= x < 1.0
  2. 0.37444887175646646
  3. >>> random.uniform(1, 10) # Random float x, 1.0 <= x < 10.0
  4. 1.1800146073117523
  5. >>> random.randint(1, 10) # Integer from 1 to 10, endpoints included
  6. 7
  7. >>> random.randrange(0, 101, 2) # Even integer from 0 to 100
  8. 26
  9. >>> random.choice('abcdefghij') # Choose a random element
  10. 'c'
  11. >>> items = [1, 2, 3, 4, 5, 6, 7]
  12. >>> random.shuffle(items)
  13. >>> items
  14. [7, 3, 2, 5, 6, 4, 1]
  15. >>> random.sample([1, 2, 3, 4, 5], 3) # Choose 3 elements
  16. [4, 1, 5]

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/966100
推荐阅读
相关标签
  

闽ICP备14008679号