For Programmers: Free Programming Magazines  


Home > Archive > Fortran > July 2004 > random_seed









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author random_seed
Kurda Yon

2004-07-28, 9:06 pm

Hi,

in the posting from 2003-09-23 13:07:12 PST
http://groups.google.com/groups?hl=...ws.t-online.com
I have found the following example of the usage "random seed":

program random3
implicit none
real, dimension(10) :: randArray
integer, allocatable, dimension(:) :: seed
integer :: size

call random_seed(size=size) ! get size of seed
allocate(seed(size)) ! allocate its space
call random_seed()
call random_number(randArray)
write(*,*) randArray
call random_seed(get=seed) ! get last value of seed
call random_seed(put=seed) ! restore seed to last value
call random_number(randArray)
write(*,*) randArray
end program random3

What I cannot understand is what functions "random_seed" performs.
In the above program I have deleted all lines related with
random_seed:

program random3
implicit none
real, dimension(10) :: randArray
integer :: size
call random_number(randArray)
write(*,*) randArray
call random_number(randArray)
write(*,*) randArray
end program random3

and obtained in such way program gives the same output as the previous
one.
Can anybody explain me what for author wanted to use "random_seed" and
why it does not work?
Jan Vorbrüggen

2004-07-28, 9:06 pm

> Can anybody explain me what for author wanted to use "random_seed" and
> why it does not work?


The seed is the internal state of a pseudo-random number generator that
determines the next number being generated. Getting the seed now and setting
it later allows you to (re-)start the sequence of numbers. As written, your
sample program could indeed dispense with all calls involving the seed,
because it calls the getting and setting back-to-back. You need to allocate
the seed to the size specified by the first call because the standard
allows each implementation to have internal state of different size.

Jan
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com