0

Well I searched for some time but couldn't get what I really need. So in Python it is as simple as it could be: random.random() gives different values every time you run the code, no need to type anything else. Thus,

for i in len(range(x)):
     x(i) = random.random()

would give me a different random array x every time I run my code.

I want to do the same thing in my Fortran 95 code but looks too complicated to me and so far I couldn't figure it out. So I find that rand() generates the same sequence every time and even if I provide some seed (rand(213) for example), though the sequence is different now, it is not different every time I run the code and I must change the seed (213 in this example) to change it. On the other hand, I find that the function random_number() is beyond my understanding when used together with random_seed(). Without it, it generates the same sequence of numbers again and again:

DO i = 1, n
  call random_number(x(i))
ENDDO

On the other hand, the arguments size, put and get are not understandable to me from this link. Can somebody explain these arguments and how to use them so that the random array would be initialized to different values every time I run the program?

francescalus
  • 30,576
  • 16
  • 61
  • 96
Peaceful
  • 4,920
  • 15
  • 54
  • 79
  • 2
    Search for SO questions with the keywords *fortran random seed*. Between them the answers will most likely explain matters clearly enough for you. – High Performance Mark Sep 04 '15 at 07:24
  • If you don't want this question closed as a duplicate I think you need to be much more specific than you have been already about what you are failing to understand. I sense, too, a hesitation on your part to try messing around with code and seeking understanding-by-doing. – High Performance Mark Sep 04 '15 at 10:54
  • I am not sure. So I tried various things and I am also looking at the link that francescalus provided. If you think that this question is duplicate, I have no issues in it being marked as duplicate. Thank you – Peaceful Sep 04 '15 at 10:57
  • It isn't too important whether we think it is a duplicate, as we can only interpret what you wrote. If the duplicate doesn't answer your question, then edit your question to better describe your problem (and why the duplicate doesn't help). – casey Sep 04 '15 at 14:51
  • I think there are valuable things we can say with regards to the implications of `random_number` and `random_seed`. The answer to the linked question makes sense to me - but I already understand such things. If you don't follow what is written there (and it will require some work to infer some things) then we can help if you can clarify which parts are missing. – francescalus Sep 04 '15 at 15:01
  • 1
    There are also other variants available, you can choose which is the most clear to you http://stackoverflow.com/questions/21352202/random-numbers-keep-coming-out-the-same-dispite-random-seed-being-used-bug-in http://stackoverflow.com/questions/32315300/generate-independent-pseudo-random-number-sequences-fortran-90 http://stackoverflow.com/questions/23875589/why-are-my-random-numbers-always-the-same This is a very common duplicate. – Vladimir F Героям слава Sep 05 '15 at 10:08

0 Answers0