vendredi 10 janvier 2020

drand and drandm in fortran are giving numbers outside of [0,1] range

here is my script below, I use implicit none because I would like to eventually implement them in a bigger program with more variables.

program testdrandm implicit none real, external :: drand, drandm, rand

    print *, 'drand', drand(0), drand(0)
    print *, 'drandm', drandm(0), drandm(0)
    print *, 'rand', rand(0), rand(0)

end program testdrandm

here is my output: drand 4.3290930E-39 -686.1465 drandm -8.9381798E+10 1.7946890E+19 rand 0.9679557 0.1896898

The first number is within range but extremely small and will give me zero values when I use it to multiply other values. Rand works but I would like to use drandm. I would like to get random numbers between 0 to 1. Please let me know if I am using this function incorrectly.




Aucun commentaire:

Enregistrer un commentaire