29 ms·
It's no better in Java. A fairly literal translation of the code [1], using the new Random::doubles method [2], gets counts like so: 166808 332743 500449
by twic 12y ago
It's no better in Java. A fairly literal translation of the code [1], using the new Random::doubles method [2], gets counts like so:
166808
332743
500449
If anything, this is even weirder than the C++ results. :rage1:
The doubles method makes each value "as if it's the result of calling the following method with the origin and bound':
double nextDouble(double origin, double bound) {
double r = nextDouble();
r = r * (bound - origin) + origin;
if (r >= bound) // correct for rounding
r = Math.nextDown(bound);
return r;
}
Which is the naive approach that Artur has been struggling against.
[1] https://bitbucket.org/snippets/twic/qqEe https://bitbucket.org/snippets/twic/qqEe
[2] https://docs.oracle.com/javase/8/docs/api/java/util/Random.html#doubles-long-double-double- https://docs.oracle.com/javase/8/docs/api/java/util/Random.h...