Last active
February 23, 2022 19:55
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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