Skip to content

Instantly share code, notes, and snippets.

@Shariar-Hasan
Last active September 7, 2023 21:32
Show Gist options
  • Save Shariar-Hasan/b4a878455b032aeb33d31a49b4b05380 to your computer and use it in GitHub Desktop.
Save Shariar-Hasan/b4a878455b032aeb33d31a49b4b05380 to your computer and use it in GitHub Desktop.
random number generate (with + without) range in javascript
// how to create random numbers
// random numbers
var rand = Math.random(); //will create random number between 0 - 1
console.log(rand);
// random numbers from 0 - rand1
var rand1 = 6;
var randomNumberZeroToRand1 = Math.floor(Math.random()*rand1);
console.log(randomNumberZeroToRand1);
// random number from rand2 to rand3
var rand2 = 100;
var rand3 = 350;
var randomNumberRand2ToRand3 = rand2 + Math.floor(Math.random()*(rand3-rand2));
console.log(randomNumberRand2ToRand3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment