|
关于RANDOM_NUMBER函数,Fortran指出他所生成的随机数范围为大于等于0且小于1,如下所述。我编写了一个程序来测试所生成的随机数的范围,发现随机数全部都为大于0且小于1的数,从来没有出现过0,不知道这个说明是不是有问题!!!
与此同时,在我另外一个计算程序里面,随机数竟然出现了1,但是概率较低,不是每次都能出现,请教下大家这是什么问题,不知道大家有没有遇到过这种情况,谢谢!!!
Purpose
Intrinsic Subroutine Returns a pseudorandom number greater than or equal to zero and less than one from the uniform distribution.
Syntax
CALL RANDOM_NUMBER (harvest)
harvest
(Output) Real. Can be an array. Pseudorandom number, 0?harvest <1, from the uniform distribution, or an array of such numbers.
Remarks
The seed for the pseudorandom number generator used by RANDOM_NUMBER can be set or queried with RANDOM_SEED. If RANDOM_SEED is not used, the processor sets the seed for RANDOM_NUMBER to a processor-dependent value.
All the random procedures (RANDOM_NUMBER, RANDOM, and RAN, and the PortLib functions DRAND, DRANDM, RAND, IRANDM, RAND, and RANDOM) use the same algorithms and thus return the same answers. They are all compatible and can be used interchangeably. (The algorithm used is a 揚rime Modulus M Multiplicative Linear Congruential Generator,?a modified version of the random number generator by Park and Miller in 揜andom Number Generators: Good Ones Are Hard to Find,?CACM, October 1988, Vol. 31, No. 10.)
Compatibility
CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB
Example
REAL x, array1 (5, 5)
CALL RANDOM_SEED()
CALL RANDOM_NUMBER(x)
CALL RANDOM_NUMBER(array1)
|
|