LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (January 2002, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 21 Jan 2002 16:41:17 -0500
Reply-To:     john.hixon@KODAK.COM
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         john.hixon@KODAK.COM
Subject:      Random Number Range
Comments: To: schmitta@CSD.UWM.EDU
Content-type: text/plain; charset=us-ascii

From: John Hixon

/*

Thomas Allen Schmitt <schmitta@CSD.UWM.EDU> asked:

>Hi All! Could someone please tell me how to pull a random number from a >uniform distribution between a specified range. For example, pull a >random number from a uniform distribution between 3.76 and 3.88.

>I'll add to what I wrote above in that I'm doing it in IML and need it in >this format:

> if t = 1 then x = ge -4.00 and lt -3.88; > else if t = 2 then x= -3.88 and lt -3.76; >. . . and so on. Thanks.

>Tom

Tom, you've already been told about the ranuni() function. Here it is used in your context (IML). Note that I did not pay much attention to your endpoints (GE or LT), so, cleaning up that detail is left for you! */

%let n=50; %let seed=987654; * Make this -1 if you want a diff random # each time you run the code; * if you keep it a fixed #, others will be able to duplicate your; * "random" numbers; proc iml; t=j(&n,1,-99999); x=j(&n,1,-99999); TargMin=j(&n,1,-99999); TargMax=j(&n,1,-99999); do i=1 to &n; TargMin[i]=-4.00+(i-1)*0.12; TargMax[i]=-4.00+(i)*0.12; t[i]=i; x[i]=TargMin[i]+0.12*ranuni(&seed); end; out=t||x||TargMin||TargMax; create junk from out [colname={'t' 'x' 'TargMin' 'TargMax'}]; append from out; quit; run; proc print data=junk; run;

*

HTH

John Hixon Eastman Kodak Co Rochester, NY USA;


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