Last active
December 29, 2015 21:25
-
-
Save codewithtyler/7ff615ff1cc4f92f387c to your computer and use it in GitHub Desktop.
Random Number Generator Algorithms for JavaScript
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 random decimal number between 0 and 1 | |
var random = Math.random(); | |
// Generate a whole number between 0 and the max number; | |
var maxNumber = 10; | |
var random = Math.floor(Math.random() * maxNumber); // Will generate a whole number between 0 and 9 | |
// Generate random whole numbers within a given range | |
var min = 25; | |
var max = 38; | |
var random = Math.floor(Math.random() * (max - min + 1)) + min // Will generate a whole number between 25 and 38 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment