Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

generating random number with a specific distribution in c

Tags:

c

i need a library with functions for generating random number, given average, standard deviation and using one of three distribution - exponential, normal or unified.

even one of the three would help. i'm looking for something like this - http://www.codeproject.com/KB/recipes/zigurat.aspx, but in c.

thanks

like image 669
Delli22 Avatar asked Sep 05 '11 06:09

Delli22


People also ask

How do you generate a random number from a given distribution?

Perhaps the most generic way to do so is called inverse transform sampling: Generate a uniform random number in [0, 1]. Run the quantile function (also known as the inverse CDF or the PPF) on the uniform random number. The result is a random number that fits the distribution.

How do you generate a random number with a predefined probability distribution?

The basic idea goes like this: start from a random point x and take a random step xnew = x + delta. evaluate the desired probability distribution in the starting point p(x) and in the new one p(xnew) if the new point is more probable p(xnew)/p(x) >= 1 accept the move.

How do you generate a random number in C?

The rand() and srand() functions are used to generate random numbers in C/C++ programming languages. The rand() function gives same results on every execution because the srand() value is fixed to 1.


1 Answers

May I recommend the GNU Scientific Library either for use or for inspiration? It has several Random Number Distributions and is designed to be used from C and C++.

like image 71
Prof. Falken Avatar answered Oct 26 '22 18:10

Prof. Falken