Last active
September 7, 2023 21:32
-
-
Save Shariar-Hasan/b4a878455b032aeb33d31a49b4b05380 to your computer and use it in GitHub Desktop.
random number generate (with + without) range in 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
// 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