Random Function

Reply
Super Contributor
Super Contributor
Posts: 440

Random Function

if i need to generate random age 10-50 will it really matter if i go by age=round(ranuni(0)*40+10) or age=int(ranuni(0)*50+10);

I mean,do i have to use the INT function when it comes to generating random numbers or it does not matter?

Also,does the seed play a  big role here?

Anyone ,please?

Thanks

Respected Advisor
Posts: 4,663

Re: Random Function

If you want ages to be whole numbers then you should use function round, int, floor or ceil. To give all ages between 10 and 50 (inclusive) equal probability, use :

age = 10 + floor(41*ranuni(-1));

PG

PG
Super Contributor
Super Contributor
Posts: 440

Re: Random Function

thanks  but why seed=-1,does that gives me better equal probability?

Super User
Posts: 3,115

Re: Random Function

If you check out the RANUNI documentation then it explains what a seed less than 0 does:

http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p1fkiqt9yga...

In summary a negative seed results in the system time being used instead of the seed so each time you run your program you get a different random number sequence. If you use the same positive seed you will get the same random sequence.

Super Contributor
Super Contributor
Posts: 440

Re: Random Function

thanks SASKiwi

SAS Super FREQ
Posts: 3,490

Re: Random Function

See the article How to generate random numbers in SAS - The DO Loop

With regard to the seed, you might also be interested in this article:

Random number seeds: Only the first seed matters! - The DO Loop

Super Contributor
Super Contributor
Posts: 440

Re: Random Function

Thanks Rick

Nice blog,nice explanation

Ask a Question
Discussion stats
  • 6 replies
  • 243 views
  • 2 likes
  • 4 in conversation