Skip to content

Instantly share code, notes, and snippets.

@Ambratolm
Last active February 23, 2022 19:55
Show Gist options
  • Save Ambratolm/44b671ce86035e727d06d6d4f140e246 to your computer and use it in GitHub Desktop.
Save Ambratolm/44b671ce86035e727d06d6d4f140e246 to your computer and use it in GitHub Desktop.
Simple random number generation functions. Generate number between two numbers. Min and Max are always included.
// Generate a integer random number between min and max (both inclusives)
function random(min = 0, max = 9) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1) + min);
}
// Generate a random decimal (float) number between min and max (both inclusives)
function randomF(min = 0.0, max = 9.0) {
return Math.random() * (max - min + 1) + min;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment