This is the mail archive of the gsl-discuss@sources.redhat.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Random Number Seed


The function you're after (at least on POSIX systems) is time in time.h 
(try man 2 time if you're on a Linux or BSD machine).  I nearly always 
seed my generator this way at the start of a program.  For instance,

#include <gsl/gsl_rng.h>
#include <time.h>                                                                                  
                                                                                                                                     
int main(int argc, char *argv[])
{
	const gsl_rng_type *T = gsl_rng_mt19937;
	gsl_rng *r = gsl_rng_alloc(T);

	gsl_rng_set(r, (unsigned long) time(NULL))

	...

}
	
Hope this helps.

Fred Ross
High Energy Physics Laboratory
University of Virginia

> Hi,
> 
> I have a question:
> When one wants to use the random number seed different than the default one (equals to 0) one can use the macro GSL_RNG_SEED=seed from the command line. I would like to use the system time as the seed and have no idea how one can use the it from the command line. Therefore I want to use the function clock() in my C program. Could you help me how the seed can be initialized from the function claock() within my c program?
> 
> Thank you for help,
> 
> Pshem
> 
> 
> 
> 
> --------------------------------------------------
> Deutsche Bank AG
> Risk Controlling
> Credit Risk Engineering & Implementation
>             /  Daily Credit Risk
> 
> Tel.:  (+44 20) 754 59676 London
> Fax:   (+44 20) 754  71060 London
> 
> ----------------------------------------------------
> 
> 
> --
> 
> This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]