jeudi 11 mai 2017

What's the absolute limit of Java ThreadLocalRandom.current().nextGaussian()?

Consider the following Java 8 code:

int floorMax = 10;
int totalRuns = 1000000000;

int[] floorCounts = new int[floorMax];

for (int i = 0; i < totalRuns; i++)
  floorCounts[
    (int) Math.floor(Math.abs(
      ThreadLocalRandom.current().nextGaussian()
    ))
    ]++;

for (int c = 0; c < floorMax; c++)
  System.out.println(
    "# of values between " + String.valueOf(c) +
      " and " + String.valueOf(c + 1) +
      ": " + floorCounts[c]);

It executes on my local machine in 42 seconds:

# of values between 0 and 1: 682679980
# of values between 1 and 2: 271828237
# of values between 2 and 3: 42795770
# of values between 3 and 4: 2633149
# of values between 4 and 5: 62319
# of values between 5 and 6: 544
# of values between 6 and 7: 1
# of values between 7 and 8: 0

What is the absolute limit of nextGaussian()?




Aucun commentaire:

Enregistrer un commentaire