From: ndl_91 on 19 Jun 2010 15:14 On 19 juin, 19:56, steve <kar...(a)comcast.net> wrote: > On Jun 19, 6:06 am, ndl_91 <nicolas.lardj...(a)gmail.com> wrote: > > > > > On 19 juin, 12:15, Allamarein <matteo.diplom...(a)gmail.com> wrote: > > > > I would get random (maybe it is more correct 'pseudorandom') numbers > > > with distribution [0,1] > > > I try this wrong code: > > > ... > > > When it runs, it provide me random.dat. > > > I can run RANDOMIZE as many times as I like, but random.dat ALWAYS > > > contains these data: > > > > 0.70 0.91 0.35 0.88 > > > 0.28 0.30 0.55 0.13 > > > 0.66 0.48 0.61 0.93 > > > 0.81 0.99 0.97 0.76 > > > 0.98 > > > > Obviously the printed result on the screen is the same > > > How should I should my code? > > > Hi. > > You need to save the seed to avoid standard initialisation. You can > > try this way. > > Hope it helps. > > Ndl > > > module m_random > > implicit none > > character(len=64), parameter, private :: fic_seed="my_seed.dat" > > ! > > contains > > ! > > subroutine reset_seed(iseed) > > implicit none > > integer, intent(in) :: iseed > > call random_seed(iseed) > > end subroutine reset_seed > > Unfortunately, your code is invalid. In the above, > iseed is the SIZE argument to random_seed via positional > argument association. SIZE is an intent(out) variable. > > -- > steve Thank you for your remark, I wrote this piece of code in a hurry. Looking at it, SIZE is rather an intent(inout) variable. Nevertheless, as I understood Allamarein's question, this code could be a starting point. Ndl
From: steve on 19 Jun 2010 15:52 On Jun 19, 12:14 pm, ndl_91 <nicolas.lardj...(a)gmail.com> wrote: > On 19 juin, 19:56, steve <kar...(a)comcast.net> wrote: > > > > > On Jun 19, 6:06 am, ndl_91 <nicolas.lardj...(a)gmail.com> wrote: > > > > On 19 juin, 12:15, Allamarein <matteo.diplom...(a)gmail.com> wrote: > > > > > I would get random (maybe it is more correct 'pseudorandom') numbers > > > > with distribution [0,1] > > > > I try this wrong code: > > > > ... > > > > When it runs, it provide me random.dat. > > > > I can run RANDOMIZE as many times as I like, but random.dat ALWAYS > > > > contains these data: > > > > > 0.70 0.91 0.35 0.88 > > > > 0.28 0.30 0.55 0.13 > > > > 0.66 0.48 0.61 0.93 > > > > 0.81 0.99 0.97 0.76 > > > > 0.98 > > > > > Obviously the printed result on the screen is the same > > > > How should I should my code? > > > > Hi. > > > You need to save the seed to avoid standard initialisation. You can > > > try this way. > > > Hope it helps. > > > Ndl > > > > module m_random > > > implicit none > > > character(len=64), parameter, private :: fic_seed="my_seed.dat" > > > ! > > > contains > > > ! > > > subroutine reset_seed(iseed) > > > implicit none > > > integer, intent(in) :: iseed > > > call random_seed(iseed) > > > end subroutine reset_seed > > > Unfortunately, your code is invalid. In the above, > > iseed is the SIZE argument to random_seed via positional > > argument association. SIZE is an intent(out) variable. > > > -- > > steve > > Thank you for your remark, I wrote this piece of code in a hurry. > Looking at it, SIZE is rather an intent(inout) variable. > Nevertheless, as I understood Allamarein's question, this code could > be a starting point. > Ndl Yes, the code is a starting point. Well, Fortran Standard says that SIZE is an INTENT(OUT) variable. Yes, an INTENT(INOUT) variable will also work. -- steve
From: Allamarein on 19 Jun 2010 18:18 I would start from this code, suggested by Tobias's link: SUBROUTINE init_random_seed() INTEGER :: i, n, clock INTEGER, DIMENSION(:), ALLOCATABLE :: seed CALL RANDOM_SEED(size = n) ALLOCATE(seed(n)) CALL SYSTEM_CLOCK(COUNT=clock) seed = clock + 37 * (/ (i - 1, i = 1, n) /) CALL RANDOM_SEED(PUT = seed) DEALLOCATE(seed) END SUBROUTINE If I understood, this subroutine generates a seed based on the actual time. When I got a seed, then I can call RANDOM_NUMBER in order to get a "genuine" random number and I avoid to get the same "random" number at any run. Perhaps I could this code (always in the website suggested by Tobias): program test_random_number REAL :: r(5,5) CALL init_random_seed() ! see example of RANDOM_SEED CALL RANDOM_NUMBER(r) end program Should it work?
From: Gib Bogle on 20 Jun 2010 03:21 Allamarein wrote: > I would get random (maybe it is more correct 'pseudorandom') numbers > with distribution [0,1] .... For some applications it's useful to specify the seed for the RV generator. Then if you record the seed value you can rerun your simulation later, to reproduce the results (this doesn't work when multi-processing).
From: Ian Bush on 20 Jun 2010 03:43
On 20 June, 08:21, Gib Bogle <g.bo...(a)auckland.no.spam.ac.nz> wrote: > Allamarein wrote: > > I would get random (maybe it is more correct 'pseudorandom') numbers > > with distribution [0,1] > > ... > For some applications it's useful to specify the seed for the RV generator. > Then if you record the seed value you can rerun your simulation later, to > reproduce the results (this doesn't work when multi-processing). Nitpick: This MAY not work when multi-processing. It depends on what you do, and probably the implementation as well, Ian |