Fortran Coder

查看: 14751|回复: 4
打印 上一主题 下一主题

[讨论] Fortran中所生成的随机数范围

[复制链接]

19

帖子

5

主题

0

精华

入门

F 币
110 元
贡献
61 点
跳转到指定楼层
楼主
发表于 2018-7-22 13:38:56 | 显示全部楼层 |只看大图 回帖奖励 |倒序浏览 |阅读模式
关于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)


分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

19

帖子

5

主题

0

精华

入门

F 币
110 元
贡献
61 点
沙发
 楼主| 发表于 2018-7-22 15:57:03 | 显示全部楼层
胡文刚 发表于 2018-7-22 15:41
单精度浮点,随机到0 的概率是 1/2147483648
双色球中奖概率为 1/17720000
前者大概是后者的  1/121 ...

只要有出现的概率,当次数达到一定程度后,总应该出现一次吧,那个程序我运行了24h,次数肯定够了,但是却没有过一次。
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-3 15:40

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表