Date: Thu, 16 Sep 2010 14:39:56 -0400 oloolo "SAS(r) Discussion" oloolo Re: how to generate 1 to 100k random numbers without zeros? To: Dale McLerran

agreed, RANTBL is extremely slow when # of bins are large, say 100K. as for the syntax perspective, it accepts 'of...' style syntax, so I usually use array to avoid tedious list of probabilities:

array _p{*} p1-p100; do j=1 to 100; _p[j]=0.01; end; seed=3454353; x=rantbl(seed, of _p[*]);

On Thu, 16 Sep 2010 11:16:05 -0700, Dale McLerran <stringplayer_2@YAHOO.COM> wrote:

>The RANTBL function shines when the number of bins is small AND >when the probability varies across bins. Here, where we are >selecting an observation from among 100K bins, the RANTBL function >would not be advisable. Moreover, since the bin probabilities >follow a uniform distribution, it is much simpler to employ >something like > >x = ceil(100000*ranuni(seed)); > > >For 10 bins with probabilities conforming to a uniform distribution, >compare > >x = rantbl(seed,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1); > >with > >x = ceil(10*ranuni(seed)); > >I would certainly prefer the latter, even though the number of >bins is not particularly large. > >Dale > >--------------------------------------- >Dale McLerran >Fred Hutchinson Cancer Research Center >mailto: dmclerra@NO_SPAMfhcrc.org >Ph: (206) 667-2926 >Fax: (206) 667-5977 >--------------------------------------- > > >--- On Thu, 9/16/10, oloolo <dynamicpanel@YAHOO.COM> wrote: > >> From: oloolo <dynamicpanel@YAHOO.COM> >> Subject: Re: how to generate 1 to 100k random numbers without zeros? >> To: SAS-L@LISTSERV.UGA.EDU >> Date: Thursday, September 16, 2010, 7:03 AM >> all replies are wonderful >> discussions, but I am a little surprised that no >> body mentioned using RANTBL to generate the random variable >> as the question >> is a discrete r.v generation problem in nature >> >> On Mon, 13 Sep 2010 10:52:22 -0700, Arthur Tabachneck >> <art297@NETSCAPE.NET> >> wrote: >> >> >Kate, >> > >> >Whether it is beneficial depends upon what you are >> trying to do. If >> >you are trying to select random numbers between 1 and >> 100000, without >> >replacement, then datanull's proposed code is the one >> offering that >> >accomplishes the task. Unless I overlooked >> something it appeared that >> >all of the other offerings would result in many of the >> same numbers >> >being picked repeatedly. >> > >> >HTH, >> >Art >> >----------- >> >On Sep 13, 8:01 am, kate <juanz...@gmail.com> >> wrote: >> >> thank you. >> >> what's the benefit of this code instead of using >> random_num = >> >> int(ranuni(0)*99999)+1 ? >> >> >> >> thanks >> >> >> >> On Sep 13, 7:53 am, "data _null_;" <datan...@gmail.com> >> wrote: >> >> >> >> >> >> >> >> > On Sep 13, 6:46 am, kate <juanz...@gmail.com> >> wrote: >> >> >> >> > > interestingly, the very first time I >> run >> >> > > random_number=int(ranuni(1))*100000, I >> got 2 zeros. which caused >> >> > > unexpected mistake in final result. >> >> >> >> > > On Sep 13, 3:48 am, Patrick <patrick.mat...@gmx.ch> >> wrote: >> >> >> >> > > > Barry >> >> >> >> > > > You will find many SAS examples >> where ceil() is used as I >> suggested. >> >> >> >> > > > I would assume that the likelyhood >> to get a exact 0 from ranuni() >> is >> >> > > > neglectable (if the underlying >> algorithm creates a 0 at all). >> >> >> >> > > > Cheers >> >> > > > Patrick- Hide quoted text - >> >> >> >> > > - Show quoted text - >> >> >> >> > PROC PLAN can produce a random permutation of >> the values 1-100000; >> >> > there will be no zero. >> >> >> >> > proc plan seed=1091883594; >> >> > factors r=100000 / noprint; >> >> > output out=r; >> >> > run; >> >> > proc print data=r(obs=100); >> >> > run; >> >> > proc print data=r(where=(r=0)); >> >> > run;- Hide quoted text - >> >> >> >> > - Show quoted text -- Hide quoted text - >> >> >> >> - Show quoted text - >>

Back to: Top of message | Previous page | Main SAS-L page