171k views
4 votes
Why does the randomNumber function only use whole numbers between 0 and 1 (basically, 0 and 1)?

User Rocki
by
4.5k points

1 Answer

5 votes

Answer:

The randomNumber function only uses whole numbers between 0 and 1 because those are the unspecified minimum and maximums to get random numbers. If you want a larger range, just specify the minimum and maximum.

Step-by-step explanation:

Example code on how to specify a larger range, replace max and min with your maximum and minimum integers.

function getRandomArbitrary(min, max) {

return Math.random() * (max - min) + min;

}

User SinisterDex
by
4.2k points