Monday, March 25, 2013

25 - generating random number in FORTRAN

In Fortran one can use 
real:: rnd
call random_number(rnd)  

to generate random numbers between [0,1]. But the problem is that if we reuses this peice of the code again, we will get exactly the same squence of random numbers. To produce a different sequece random number each time, the generator can be seede in a number of ways such as:

integer:: count, seed
real:: rnd
call system_clock(count)
seed=count
call random_seed(put=seed)
call random_number(rnd)

more infos can be found in this website.

No comments:

Post a Comment