Skip to content

Instantly share code, notes, and snippets.

@sayyedhammadali
Last active March 11, 2023 04:33
Show Gist options
  • Save sayyedhammadali/aa098e46b9b1aab4b8e1729a66bc695d to your computer and use it in GitHub Desktop.
Save sayyedhammadali/aa098e46b9b1aab4b8e1729a66bc695d to your computer and use it in GitHub Desktop.
Get a random number in a specific range
const randomNumberInRange = (min = 0, max = 100) => Math.floor(Math.random() * (max - min + 1)) + min;
randomNumberInRange()
// Result: Default random number range is 0 - 100, so you get a number between 0 and 100.
randomNumberInRange(100, 200)
// Result: You will get a random number between 100 and 200, where 100 is min range and 200 is max range.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment