How tocreate a random number between 0.3 and 1.
I know that Math.random()
creates a number between 0 and 1.
However im using css scale and below 0.3 is to small.
How tocreate a random number between 0.3 and 1.
I know that Math.random()
creates a number between 0 and 1.
However im using css scale and below 0.3 is to small.
If you want an equal chance of any number over the range 0.3 to 1, then
Math.random() * 0.7 + 0.3
Multiplying a number from 0 to 1 by 0.7 will give you a number from 0 to 0.7, and the + 0.3 will then get you to the range 0.3 to 1.0.
If you wanted to get between 0.3 and 1, you would put:
var min = 0.3,
max = 1,
var answer = (Math.random() * (max - min) + min).toFixed(4);
alert(answer);
0.3 is an our start number1 is a number of possible results Or
(Math.random() * (1 - 0.3) + 0.3).toFixed(4)
toFixed is used to convert a number into a string,