Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

RANDOM_SEED() and RANDOM_NUMBER()

johansoderstrom
Beginner
622 Views

Hi again

I am trying to obtain a set of random numbers and I use this code:

USE DFPORT

REAL T1

CALL RANDOM_SEED()

CALL RANDOM_NUMBER(T1)

Now this does give me a random number, based on the date and time... But if I call it several times in a row (fast) it seems to me that the Random numbers do not change (I convert them into a Gaussian distribution and I typically get a set of random numbers but the same number being repeated over 20 times until it changes) - as the time is the same... is there any way of initializing RANDOM_SEED() with time and date, but with...say... microseconds instead of seconds (or what is used in the routine right now)... to get "more" randomized numbers...

I hope this makes sence...

Thanks,

Johan S

0 Kudos
1 Reply
andi_zuend
Beginner
622 Views
Hi,

I guess your target is to get a new random number at every call to RANDOM_NUMBER, so you only need once (or never, see the User and Reference Guides) to call RANDOM_SEED. This is just to seed the random number generator at the beginning, thus, it shouldn't be called in a loop.

best,
Andi
0 Kudos
Reply