Programming 板


在今年公告 (2007/06/05) 的 ISO1539 Fortran 标准规格中,并没有说 Call RANDOM_SEED 会依据时间自动初始化。 可能是特定编译器加进去的延伸功能。例如 IVF 线上手册有提到有此功能,但不见得其他编译器会有。 标准规格: 13.7.144 RANDOM SEED ([SIZE, PUT, GET]) 1 Description. Restart or query the pseudorandom number generator used by RANDOM NUMBER. 2 Class. Subroutine. 3 Arguments. There shall either be exactly one or no arguments present. SIZE (optional) shall be scalar and of type default integer. It is an INTENT (OUT) argument. It is assigned the number N of integers that the processor uses to hold the value of the seed. PUT (optional) shall be a default integer array of rank one and size  N. It is an INTENT (IN) argument. It is used in a processor-dependent manner to compute the seed value accessed by the pseudorandom number generator. GET (optional) shall be a default integer array of rank one and size  N It is an INTENT (OUT) argument. It is assigned the current value of the seed. 4 If no argument is present, the processor assigns a processor-dependent value to the seed. 5 The pseudorandom number generator used by RANDOM NUMBER maintains a seed that is updated during the execution of RANDOM NUMBER and that may be speci ed or returned by RANDOM - SEED. Computation of the seed from the argument PUT is performed in a processor-dependent manner. The value returned by GET need not be the same as the value speci ed by PUT in an immediately preceding reference to RANDOM SEED. For example, following execution of the statements 6 CALL RANDOM_SEED (PUT=SEED1) CALL RANDOM_SEED (GET=SEED2) 7 SEED2 need not equal SEED1. When the values di er, the use of either value as the PUT argument in a subsequent call to RANDOM SEED shall result in the same sequence of pseudorandom numbers being generated. For example, after execution of the statements 8 CALL RANDOM_SEED (PUT=SEED1) CALL RANDOM_SEED (GET=SEED2) CALL RANDOM_NUMBER (X1) CALL RANDOM_SEED (PUT=SEED2) CALL RANDOM_NUMBER (X2) 9 X2 equals X1. 10 Examples. 11 CALL RANDOM_SEED ! Processor initialization CALL RANDOM_SEED (SIZE = K) ! Puts size of seed in K CALL RANDOM_SEED (PUT = SEED (1 : K)) ! Define seed CALL RANDOM_SEED (GET = OLD (1 : K)) ! Read current seed Intel Visual Fortran 9.1 有提到省略参数会用日期与时间进行初始化: RANDOM_SEED Intrinsic Subroutine: Changes or queries the seed (starting point) for the pseudorandom number generator used by RANDOM_NUMBER. Syntax CALL RANDOM_SEED ([size] [, put] [, get]) size (Output; optional) Must be scalar and of type integer. Set to the number of integers (N) that the processor uses to hold the value of the seed. put (Input; optional) Must be an integer array of rank one and size greater than or equal to N. It is used to reset the value of the seed. get (Output; optional) Must be an integer array of rank one and size greater than or equal to N. It is set to the current value of the seed. No more than one argument can be specified. If no argument is specified, a random number based on the date and time is assigned to the seed. You can determine the size of the array the processor uses to store the seed by calling RANDOM_SEED with the size argument (see the second example below). Examples Consider the following: CALL RANDOM_SEED ! Processor initializes the ! seed randomly from the date ! and time CALL RANDOM_SEED (SIZE = M) ! Sets M to N CALL RANDOM_SEED (PUT = SEED (1 : M)) ! Sets user seed CALL RANDOM_SEED (GET = OLD (1 : M)) ! Reads current seed The following shows another example: INTEGER I INTEGER, ALLOCATABLE :: new (:), old(:) CALL RANDOM_SEED ( ) ! Processor reinitializes the seed ! randomly from the date and time CALL RANDOM_SEED (SIZE = I) ! I is set to the size of ! the seed array ALLOCATE (new(I)) ALLOCATE (old(I)) CALL RANDOM_SEED (GET=old(1:I)) ! Gets the current seed WRITE(*,*) old new = 5 CALL RANDOM_SEED (PUT=new(1:I)) ! Sets seed from array ! new END ==> 本文由 "Ray <[email protected]>" > 於 news:4WXU2R%24Jr7%40bbs.ccns.ncku.edu.tw 发表 > 感谢回答 > 但是我加入CALL RANDOM_SEED之後 > 每次执行出来的乱数还是一样 > 我加入的地方是在random_number之前 > 例: > call random_seed() > call random_number(popu) > Build程式之後,每次Excute出来的乱数都一样 > 我问了google之後,找到关於random_seed的使用 > http://www.okok.org/cgi-bin/ut/topic_show.cgi?id=157388&h=1&bpg=1&age=30 > 他说: "random_seed()产生的种子是由当前计算机的日期和时间组成" > 而且 "取决于中间语句的执行时间" > 他加入了一个很长的回圈,故意让程式执行久一点 >  do i=1, 1e10 >  end do > 之後再呼叫random_seed(),果然乱数就不一样了 > 该不会Fortran每次想产生不同乱数都要这麽麻烦吧...?? > > ※ 引述《[email protected] (琏琏)》之铭言: > > 贴错函数。 > > CALL RANDOM_NUMBER (harvest) > > 这个是传回乱数。 > > 纯粹设乱数种子: > > CALL RANDOM_SEED ([size] [, put] [, get]) > > ==> 本文由 "琏琏 <[email protected]>" > > > 於 news:3CB93BFB9C0942BA9FABE2E445D16673%40c2e6400 发表 > > > Fortran 90 的标准应该是 > > > CALL RANDOM_NUMBER (harvest) > > > SRAND 是 Intel Fortran 提供的延伸函式,并不被其他的 Fortran 编译器支援。 > -- 风禹科技验证有限公司 ASP.NET Web News Reader 0.2.7 UTF-8 Beta 网站地图 http://tlcheng.twbbs.org/wwwmap.htm 流域防洪/区域水资源/徐昇网/玫瑰图/语音通讯 文章与程式 Basic/Fortran/Windows API/.Net/辅助说明档 原始码、文章与讨论 微软程式设计、系统管理使用新技术论坛讨论区,网友回覆後即时简讯、电子邮件通知: MSDN: http://forums.microsoft.com/msdn-cht/default.aspx?siteid=14 TechNet: http://forums.microsoft.com/technet-cht/default.aspx?siteid=23 -- ASPNET News Reader http://tlcheng.twbbs.org/News/Reader.aspx RSS 2.0 http://tlcheng.twbbs.org/News/rss2.aspx?Action=List&Newsgroup=tw.bbs.comp.language







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草
伺服器连线错误,造成您的不便还请多多包涵!
「赞助商连结」






like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Tech_Job站内搜寻

TOP