CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   how to generate random number in Fortran ? (https://www.cfd-online.com/Forums/main/5931-how-generate-random-number-fortran.html)

tang April 1, 2003 10:14

how to generate random number in Fortran ?
 
Any one has experience to generate a random number in Fortran? using

random_number(a), ...

What's the details?

Thanks

tang

R. Andom. April 1, 2003 13:47

Re: how to generate random number in Fortran ?
 
Check Numerical Recipes in FORTRAN online......

littlelz April 2, 2003 09:48

Re: how to generate random number in Fortran ?
 
for fortran 90, use: CALL RANDOM_NUMBER(random), then the variable random can be used!

tang April 2, 2003 09:54

Re: how to generate random number in Fortran ?
 
but use

CALL RANDOM_NUMBER

gives a same number at different runs. That is, it is not random if different runs are made.

Using 'seed' may solve the problem? then how?


Vladimir Krejci April 2, 2003 11:12

Re: how to generate random number in Fortran ?
 
I am not sure but all random number generators produce the same number if you use the same number for their initialization. If you want to get a number which is more random (for you) initialize the generator with e.g. actual time on your computer.

hope it helps

vladimir

tang April 2, 2003 11:23

Re: how to generate random number in Fortran ?
 
But how to set actual time as the seed? What's the command in Fortran?

Thanks

T

Nashat April 2, 2003 17:48

Re: how to generate random number in Fortran ?
 
These links might be helpful:

http://rsc.anu.edu.au/~harry/COURSES...TH/node73.html

http://www.fortran.com/fortran/random1.f90

http://www.fortran.com/fortran/random2.f90

http://www.fortran.com/fortran/kiss.f90

http://www.library.cornell.edu/nr/nr_index.cgi

The system random generator is sometimes not as random as you would like it to be. The routines in Numerical Recepies are pretty good.

Regards.

tang April 2, 2003 17:58

thanks to your all three
 
Dear Nashat, etc

Thanks a lot

T


All times are GMT -4. The time now is 23:32.