3

How can I compute random number between 0 inclusive and 1 inclusive? When I have Math.random() it is returning 0-0.9999999

I did not find any solution for that.

edit: I think that it could be somehow this way:

const precision = 1000
let c = 0
let min = 2
let max = -2

while(c !== 20000){
   c++;
   let r = (Math.round(Math.random()*precision)/precision)/0.9999999999999;
   r = Math.round(r*precision)/precision
   max = Math.max(r, max)
   min = Math.min(r, min)
 }
console.log('max:', max, 'min:', min)
Dawe
  • 562
  • 1
  • 9
  • 19

1 Answers1

0

Here is what you're looking for.

Examples #4 on the Mozilla Developer Network