By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
 424,855 Members | 1,970 Online + Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,855 IT Pros & Developers. It's quick & easy.

# random numbers in log domain

 P: n/a 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 Feb 3 '07 #1
Share this Question
1 Reply

 P: n/a jo*********@gmail.com wrote: 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. a) Exponentiating uniformly distributed random numbers in (0,0.5) will not yield uniformly distributed random numbers between (-inf,-0.69...). b) You cannot be serious about -inf; or you cannot be serious about being uniformly distributed. There is no meaningfull uniform distribution on (-inf,-0.69...). You have to truncate the domain somewhere. c) ( -0.7 - std::rand() ) is uniformly distributed in a domain pretty close to the one you want (since you have to truncate anyhow). You could also rescale the std::rand() component by a constant factor. d) If you need to control the quality of the random number generator, or if you prefer a different distribution, have a look into tr1. Best Kai-Uwe Bux Feb 3 '07 #2

### This discussion thread is closed

Replies have been disabled for this discussion. 