Riju21

24_random

Mar 29th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. import random
  2.  
  3. # rand 0 to 1
  4. # -----------------
  5.  
  6. # myRand = random.random()
  7. # print(myRand)
  8.  
  9. # rand 0 to 1 int
  10. # -----------------
  11.  
  12. # myRand = random.randint(1,12)
  13. # print(myRand)
  14.  
  15. # rand array
  16. # --------------
  17.  
  18. # myArr = ['python', 'js', 'php', 'c#']
  19. # myRand = random.choice(myArr)
  20. # print(myRand)
  21.  
  22. # rand list
  23. # ---------------
  24.  
  25. # myArr = ['python', 'js', 'php', 'c#']
  26. # myRand = random.choices(myArr, k=4)
  27. # print(myRand)
  28.  
  29. # shuffle
  30. # --------------
  31.  
  32. # myRand = list(range(1, 11))
  33. # random.shuffle(myRand)
  34. # print(myRand)
  35.  
  36. # random unique value
  37. # --------------------
  38. myArr = list(range(1, 21))
  39. uniqueRand = random.sample(myArr, k=6)   # random unique 6 value in list
  40. print(uniqueRand)
  41.  
  42. # ------------------
  43. # more on documentation
  44. #-------------------
Advertisement
Add Comment
Please, Sign In to add comment