4 ms·
while(u === 0) u = Math.random(); //Converting [0,1) to (0,1) If that's the purpose, the loop in question does not do it. 1 is still out of bounds, only now on
by kqr 5y ago
while(u === 0) u = Math.random(); //Converting [0,1) to (0,1)
If that's the purpose, the loop in question does not do it. 1 is still out of bounds, only now only 0 is too.
If you want what the comment says, 1-Math.random() does it very simply.
- jinwoo68 5y agoBut Math.random() returns a value in the range of [0, 1), that is it never returns 1. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- kqr 5y agoWow, I completely misread the comment in the code. Sorry.
- bit-101 5y ago1 - Math.random() would result in (0,1]