Skip to content

Instantly share code, notes, and snippets.

@codewithtyler
Last active December 29, 2015 21:25
Show Gist options
  • Save codewithtyler/7ff615ff1cc4f92f387c to your computer and use it in GitHub Desktop.
Save codewithtyler/7ff615ff1cc4f92f387c to your computer and use it in GitHub Desktop.
Random Number Generator Algorithms for JavaScript
// 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