Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // True or False
- const trueOrFalse = () =>
- Boolean(Math.random() > .5)
- // Random Float
- const randomFloat = (min, max) =>
- Math.random() * (max - min) + min
- // Random Number
- const randomNumber = (min, max) =>
- Math.floor(Math.random() * (max - min)) + min
- // Random Number (Including Max Value)
- const randomNumberInclusive = (min, max) =>
- Math.floor(Math.random() * (max - min + 1)) + min
- // Pick a Random Item From an Array
- const randomArrayItem = (arr) =>
- arr[Math.floor(Math.random() * arr.length)]
- // Pick a Random Object Property
- const randomObjectProperty = (obj) => {
- let arr = Object.keys(obj)
- return obj[arr[Math.floor(Math.random() * arr.length)]]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement