mercredi 29 mars 2017

RANDOM_NUMBER: how to fix the random number sequence

I coded a Monte Carlo method that makes many calls to RANDOM_NUMBER. I would like it to use either a fixed random number sequence, which in the end is supposed to have the algorithm to always give the same answer, OR a different sequence at each run.

In order to achieve this, before any call to RANDOM_NUMBER, I do this, just once:

IF (ISRDNSD) THEN
  CALL init_random_seed()
ELSE
  CALL RANDOM_SEED(SIZE=G)
  allocate(SEED(1:G))
  SEED = SEEDINIT
  CALL RANDOM_SEED(PUT=SEED)
END IF

The ELSE being the "fixed random sequence" code. Since SEEDINIT is a constant PARAMETER, I expected the Markov Chain to be the same at each run; but it is not the case; i.e., the random number sequence appears to be different each time.

Any clue?




Aucun commentaire:

Enregistrer un commentaire