samedi 6 juin 2015

Uniform real distributions near zero

Is there ever any call for a floating-point approximation of a continuous uniform distribution contrasted with (what appears to be more popular) a discrete uniform distribution?

To produce an arbitrary-precision random value quantised to a floating-point type, I'd expect something along the lines of:

double rand0to1(void) {
  int exp = -53;
  while (random_bit() == 0) exp--;
  return ldexp((double)((1L << 52) | random_52bits()), exp);
}

What appears to be common is:

double rand0to1(void) {
  return ldexp((double)random_53bits(), -53);
}

Obviously the former being an approximation of something impossible to achieve is a big black mark for it, but I wonder if there are cases where the guarantee that the mantissa will always be fully randomised becomes useful if the result happens to be small.




Aucun commentaire:

Enregistrer un commentaire