SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 613|回复: 0
打印 上一主题 下一主题

Random Number Seeds: NOT only the first one matters!

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2012-1-31 00:51:40 | 只看该作者

Random Number Seeds: NOT only the first one matters!

From oloolo's blog on SasProgramming


<p><a href="http://feedads.g.doubleclick.net/~a/hGi5ZqD3K76tsjuRfn4ZY3p_7-g/0/da"><img src="http://feedads.g.doubleclick.net/~a/hGi5ZqD3K76tsjuRfn4ZY3p_7-g/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/hGi5ZqD3K76tsjuRfn4ZY3p_7-g/1/da"><img src="http://feedads.g.doubleclick.net/~a/hGi5ZqD3K76tsjuRfn4ZY3p_7-g/1/di" border="0" ismap="true"></img></a></p>Today, Rick (blog @ <a href="http://blogs.sas.com/content/iml/" target="_blank">here</a>) wrote an&nbsp;<a href="http://blogs.sas.com/content/iml/2012/01/30/random-number-seeds-only-the-first-seed-matters/?utm_source=feedburner&amp;utm_medium=feed&amp;utm_campaign=Feed%3A+TheDoLoop+%28The+DO+Loop%29" target="_blank">article</a> about random number seed in SAS to be used in random number functions in DATA Step. Rick noticed when multiple random number functions are called using different seeds, only the first one matters. <br />
<br />
This is so true. In fact, SAS Manual also has a comprehensive writting on this issue,&nbsp;namely, how to control seeds for each iteration of the random number generation process and how to generatie multiple statistically independent streams of random numbers, see <a href="http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p026ygl6toz3tgn14lt4iu6cl5bb.htm#p04slf135yfs1sn1vrvrvso072d3" target="_blank">here</a>. In fact, sasCommunity.org also has an article about this issue, see <a href="http://www.sascommunity.org/wiki/How_the_SAS_Random_Number_Generators_Work" target="_blank">here</a>.<br />
<br />
To&nbsp;echo Rick's post,&nbsp; there is a way to control the seed so that NOT only the first one matters: use CALL routines which by theory will generate computationally independent random number sequence. But if the two seeds are too close, the generated sequences may not be statistically independent. Again, refer to the SAS manual for details.<br />
<br />
<br />
<pre style="background-color: #ebebeb; border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; border-right: #999999 1px dashed; border-top: #999999 1px dashed; color: #000001; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 100%;"><code>

data normal;
   seed1 = 11111;
   seed2 = 22222;
   seed3 = 383333;
   do i = 1 to 1000;
      call rannor(seed1, x1);
      call rannor(seed2, x2);   
      call rannor(seed3, x3);
   x4=rannor(seed2);
   x5=rannor(seed3);
      output;
   end;
run;

proc sgscatter data=normal;
   matrix x1-x5/ markerattrs = (size = 1);
run;

</code></pre><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29815492-5189434209973827446?l=www.sas-programming.com' alt='' /></div><img src="http://feeds.feedburner.com/~r/SasProgramming/~4/E2VhkyIM6Rk" height="1" width="1"/>
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2025-5-7 03:19 , Processed in 0.087838 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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