Created by
Tom Anderson
| import java.util.Random;
import java.util.stream.DoubleStream;
public class NotVeryRandom {
public static void main(String[] args) {
Random gen = new Random();
double from = (1L << 52);
double to = from + 2;
DoubleStream dis = gen.doubles(1000000, from, to + 1);
int[] bucket = new int[3];
dis.forEach(r -> {
int b = (int) (r - from);
if (b >= 3) {
System.out.println(String.format("foo: %d %f", b, r));
}
bucket[b]++;
});
for (int i : bucket) {
System.out.println(String.format("%d", i));
}
}
}
|
Representative output:
HN thread: https://news.ycombinator.com/item?id=9352905