0

I am trying to create a list of random numbers (integers) in fortran 77 but can't quite make it work.

My problem is a want a list of N random integers, say N = 100. But also, I want the random numbers to only appear in a range between 1 and N.

So if I make:

       do 1001 j=1, N
           ar = IRAND()
           print*, j,ar
 1001 continue

That just gives me a list of integers from 0 through 2147483647.

Is there a way to change the range in IRAND()? or quick fix at least?

Mac
  • 991
  • 3
  • 11
  • 22
  • That's just it (I think) ... I am just using the inbuilt irand command exactly like above. – Mac Dec 30 '20 at 22:31
  • A way to generate integers within a range can be found in answer to [this other question](https://stackoverflow.com/q/23057213/3157076). – francescalus Dec 30 '20 at 22:31
  • That's Fortran 95 though isn't it? I seen it before but can't make it work as my version won't recognize the command :( – Mac Dec 30 '20 at 22:33
  • 1
    There is no `irand` function in Fortran (77 or otherwise). Your compiler or other system may provide one, but we need details of that. – francescalus Dec 30 '20 at 22:34
  • I am using Force 3.0. and was thinking this was an inbuilt command as I seen it in a bunch of places such as here, where I got the command from: https://docs.oracle.com/cd/E19957-01/805-4942/6j4m3r8vr/index.html – Mac Dec 30 '20 at 22:36
  • The linked question is about C rather than Fortran, but it's actually applicable: C's default RNG behaves just like the `irand` you link to. You can do the same manipulation, just translating to Fortran (the algorithm is the important part). The `irand` there has no inbuilt alternative. Alternatively, there are the other approaches using Fortran RNGs which are like the previous question. – francescalus Dec 30 '20 at 22:47
  • Did you manage to adapt the C to solve your problem? – francescalus Dec 31 '20 at 20:47
  • No I haven't :( really beginner here and don't really know C either, so might take me a while. Thank you for pointing that out though. – Mac Jan 01 '21 at 22:04

0 Answers0