Advertisement
Guest User

Untitled

a guest
May 30th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. // True or False
  2. const trueOrFalse = () =>
  3. Boolean(Math.random() > .5)
  4.  
  5. // Random Float
  6. const randomFloat = (min, max) =>
  7. Math.random() * (max - min) + min
  8.  
  9. // Random Number
  10. const randomNumber = (min, max) =>
  11. Math.floor(Math.random() * (max - min)) + min
  12.  
  13. // Random Number (Including Max Value)
  14. const randomNumberInclusive = (min, max) =>
  15. Math.floor(Math.random() * (max - min + 1)) + min
  16.  
  17. // Pick a Random Item From an Array
  18. const randomArrayItem = (arr) =>
  19. arr[Math.floor(Math.random() * arr.length)]
  20.  
  21. // Pick a Random Object Property
  22. const randomObjectProperty = (obj) => {
  23. let arr = Object.keys(obj)
  24. return obj[arr[Math.floor(Math.random() * arr.length)]]
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement