```Date: Mon, 21 Jan 2002 16:41:17 -0500 Reply-To: john.hixon@KODAK.COM Sender: "SAS(r) Discussion" 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 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