Description
The UnitSphereSampler for 1 dimension currently creates a sample from a standard normal distribution and then normalises it to unit length. This can create values that are not 1 or -1.
The following code shows this occurs approximately 14% of the time:
final UniformRandomProvider rng = RandomSource.create(RandomSource.XO_RO_SHI_RO_128_PP, 0x1a2b3cL); final UnitSphereSampler generator = new UnitSphereSampler(1, rng); int count = 0; int size = 1000000; for (int i = size; i-- > 0; ) { final double[] v = generator.nextVector(); if (Math.abs(v[0]) != 1.0) { count++; } } System.out.printf("%d / %d (%.3f)%n", count, size, 100.0 * count / size);
Outputs:
139977 / 1000000 (13.998)
This can be fixed by switching the sampling algorithm to use a bit from the random generator to pick either a 1 or -1 for the return value. This can be fixed as part of RNG-129 which is creating specialisations for sampling for lower order dimensions.