J
johntilster
How do I get uniform random numbers in the log domain? I need a random
number in the log domain between -infinity and -0.69314718, which is
equivalent to a range from 0 to 0.5.
I usually use this code to get a uniform random number between, say, 0
and 0.5:
double r = lowest + range * rand() / (RAND_MAX + 1.0);
But it won't work in the log domain when my lowest is -inf, and the
range is also infinite? I have a costly numberical procedure and
cannot afford to exponentiate the numbers that are coming in (-inf ->
0, -0.69314718 -> 0.5). So it would be good to get a random number
directly in the log domain.
Thanks!
John
number in the log domain between -infinity and -0.69314718, which is
equivalent to a range from 0 to 0.5.
I usually use this code to get a uniform random number between, say, 0
and 0.5:
double r = lowest + range * rand() / (RAND_MAX + 1.0);
But it won't work in the log domain when my lowest is -inf, and the
range is also infinite? I have a costly numberical procedure and
cannot afford to exponentiate the numbers that are coming in (-inf ->
0, -0.69314718 -> 0.5). So it would be good to get a random number
directly in the log domain.
Thanks!
John