help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] random number distributions


From: Eric Smoll
Subject: Re: [Help-gsl] random number distributions
Date: Fri, 26 Sep 2014 15:42:40 -0600

Apologies,

Looking through the help-gsl archives, Daniel Farrell provided a reasonable
solution in this thread:
http://lists.gnu.org/archive/html/help-gsl/2008-02/msg00039.html

Further comments are always welcome if anyone has any.

Best,
Eric

On Fri, Sep 26, 2014 at 2:50 PM, Eric Smoll <address@hidden> wrote:

> Hello,
>
> I am interested in using the random number distributions provided here:
>
>
> https://www.gnu.org/software/gsl/manual/html_node/Random-Number-Distributions.html
>
> Ideally, I would like to make an executable that will return a random
> value according to a specified distribution on each call. It seems like the
> recommended usage of these functions will produce deterministic output on
> each run if the seed is the same (e.g., see
> https://www.gnu.org/software/gsl/manual/html_node/Random-Number-Distribution-Examples.html#Random-Number-Distribution-Examples
> ). I could set the seed to a new value on each call (GSL_RNG_SEED=2 ./tmp)
> but I am wondering if there is a better way.
>
> From the last example shown here
> https://www.gnu.org/software/gsl/manual/html_node/Random-Number-Distribution-Examples.html#Random-Number-Distribution-Examples
> :
>
> [ Desktop ] $ cat tmp.c
> #include <stdio.h>
> #include <gsl/gsl_cdf.h>
>
> int
> main (void)
> {
>   double P, Q;
>   double x = 2.0;
>
>   P = gsl_cdf_ugaussian_P (x);
>   printf ("prob(x < %f) = %f\n", x, P);
>
>   Q = gsl_cdf_ugaussian_Q (x);
>   printf ("prob(x > %f) = %f\n", x, Q);
>
>   x = gsl_cdf_ugaussian_Pinv (P);
>   printf ("Pinv(%f) = %f\n", P, x);
>
>   x = gsl_cdf_ugaussian_Qinv (Q);
>   printf ("Qinv(%f) = %f\n", Q, x);
>
>   return 0;
> }
>
> [ Desktop ] $ gcc -Wall -I/usr/include -c tmp.c
>
> [ Desktop ] $ gcc -L/usr/lib tmp.o -lgsl -lgslcblas -lm -o tmp
>
> [ Desktop ] $ ./tmp
> prob(x < 2.000000) = 0.977250
> prob(x > 2.000000) = 0.022750
> Pinv(0.977250) = 2.000000
> Qinv(0.022750) = 2.000000
>
> [ Desktop ] $ ./tmp
> prob(x < 2.000000) = 0.977250
> prob(x > 2.000000) = 0.022750
> Pinv(0.977250) = 2.000000
> Qinv(0.022750) = 2.000000
>
> [ Desktop ] $ ./tmp
> prob(x < 2.000000) = 0.977250
> prob(x > 2.000000) = 0.022750
> Pinv(0.977250) = 2.000000
> Qinv(0.022750) = 2.000000
>
> Best,
> Eric
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]