6 ms·
It should be floor right? Math.floor(Math.random()*userAgents.length)
by namdnay 5y ago
It should be floor right? Math.floor(Math.random()*userAgents.length)
- lern_too_spel 5y agoThere's a built-in method for randomly selecting an int in a range. Use that.
- csears 5y agoAre you thinking of the Lodash random() function? Or Crypto.getRandomValues()?
- lern_too_spel 5y agohttps://docs.oracle.com/javase/8/docs/api/java/util/Random.html#nextInt-int- https://docs.oracle.com/javase/8/docs/api/java/util/Random.h...
- homami 5y agoYeah. > The java.lang.Math.random() method returns a pseudorandom double type number greater than or equal to 0.0 and less than 1.0.
- lern_too_spel 5y agofloor is unnecessary. The cast does it for you. The problem is that a random double is not going to be evenly distributed into length equal parts unless length is a power of 2.