[Top][All Lists]

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

Re: [Help-gsl] random number sequence

From: Frank Reininghaus
Subject: Re: [Help-gsl] random number sequence
Date: Tue, 20 May 2008 00:04:18 +0200
User-agent: KMail/1.9.9


the problem is here:

On Monday 19 May 2008 22:58:08 Sergey Mkrtchyan wrote:
>       srand(time(NULL));

time (NULL) returns the seconds elapsed since January 1, 1970, so it's clear 
that instances of your program that get started during the same second will 
have their random number generator initialised to the same value and will 
therefore yield the same results.

A possible workaround could be to use the function gettimeofday () which 
returns the current time with a better resolution (should work at least on 
Linux), see

You have to add #include <sys/time.h> to your source file, and then

struct timeval tv;
gettimeofday (&tv, NULL);

leaves you with the number of seconds since 1970 in tv.tv_sec and microseconds 
in tv.tv_usec.

A better idea might be to pass the random seed as an argument to each instance 
of your program (if that's easily possible with the system you use to submit 
the jobs to the cluster), e.g., you would run

program 1
program 2
program 3

or something like that. This would make it 100% sure that each process yields 
different results, and moreover, your results would be reproducible.

I hope I could help you!

reply via email to

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