473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

random numbers in log domain

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
1 1648
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: drs | last post by:
Is there any way to generate random numbers based on arbitrary real valued functions? I am looking for something like random.gauss() but with natural log and exponential functions. thanks, -d
21
by: Marc Dansereau | last post by:
Hi all I am new to this forum and to the c programming language. If I understand, the random() function in C return numbers that follow a uniform distribution U(0,1). Can somebody know how to...
5
by: user | last post by:
Hello i call it in almost same time (from two different threads): Random rand = new Random(); id=rand.Next(65535); and i often receive the same results. Is it possible ? How windows count this...
6
by: DarthBob88 | last post by:
Problem: Getting a random number, an integer. between 0 and 100. I've tried rand() % 100 +1, but that hasn't been very random. Any suggestions? Story: I'm trying to write a simple guessing game....
104
by: fieldfallow | last post by:
Hello all, Is there a function in the standard C library which returns a prime number which is also pseudo-random? Assuming there isn't, as it appears from the docs that I have, is there a...
12
by: Jim Michaels | last post by:
I need to generate 2 random numbers in rapid sequence from either PHP or mysql. I have not been able to do either. I get the same number back several times from PHP's mt_rand() and from mysql's...
10
by: muttaa | last post by:
Hi everybody, May i know how to write a code that generates random numbers as many times as one would want ? i.e. like the standard function 'rand()' or may i get the basic logic behind it ? ...
13
by: Peter Oliphant | last post by:
I would like to be able to create a random number generator that produces evenly distributed random numbers up to given number. For example, I would like to pick a random number less than 100000,...
24
by: pereges | last post by:
I need to generate two uniform random numbers between 0 and 1 in C ? How to do it ? I looked into rand function where you need to #define RAND_MAX as 1 but will this rand function give me ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.