Need help on using RANDOM_SEED

I would like to generate the same set of random numbers each time I execute a program. The problem is that each time I run it, the random numbers are different because they are seeded by a different value. Here is my program:

program test
  implicit none
  real :: rand_num
  integer :: index

  call random_seed()
  do index = 1,10
    call random_number(rand_num)
    print*,rand_num
  end do

end program test

So in order to seed with the same value at each execution, one must put an argument in random_seed() that will seed with the same value each time.

The problem is that when I try ‘random_seed(1)’ or ‘random_seed(put=1)’, neither work as the compiler comes up with an error saying

PGF90-S-0074-Illegal number or type of arguments to random_seed - keyword argument size (rand_test.f90: 6)

How do I then use random_seed to force the same seed at each execution of the program?

Hi Tom,

Your on the right track. The only correction is that the put argument to random_seed needs to be an array.

% cat rand.f90 
program test
  implicit none
  real :: rand_num
  integer :: index, seeds(2)
  seeds(1)=1
  call random_seed(put=seeds)
  do index = 1,10
    call random_number(rand_num)
    print*,rand_num
  end do
end program test

Alternatively, you can set the environment variable “STATIC_RANDOM_SEED” to “YES” to have the PGI runtime use a static instead of variable initial seed.

Hope this helps,
Mat