Recently, SAS Global Forum announced the call for papers for the 2011 conference to be held at Caesars Palace in Las Vegas.

Since the conference is in Las Vegas, I’ve been thinking a lot about games of chance: blackjack, craps, roulette, and the like. You can analyze these games by computing the odds of certain events in a probability model. Or you can be lazy, like me, and let the computer do the work by running a simulation to compute the odds of certain outcomes.

Random samples are the basis of every simulation. If you do not sample efficiently, then your simulation is doomed to take a long time. In SAS/IML software, you can generate random samples by using the RANDGEN subroutine. Novice programmers often use RANDGEN inefficiently and generate one random observation at a time within a loop. Don’t do it!

To generate, say, 1000 random samples from a uniform distribution on [0, 1], simply allocate a vector of length 1000 and call RANDGEN:

```proc iml; u = j(1000, 1); /** allocate 1000 x 1 vector **/ call randgen(u, "Uniform"); /** random sample from uniform distribution **/```

If you want to simulate 1000 dice rolls, transform the uniform variates into the range {1, 2, 3, 4, 5, 6}:

`rolls = ceil(6*u); /** 1 through 6 **/`

If you are interested in simulating outcomes from a single-zero roulette wheel, transform the uniform variates into the range {0, 1, 2, …, 36}:

`roulette = floor(37*u); /** 0 through 36 **/`

Incidentally, Caesars Palace has one single-zero roulette wheel on the main casino floor. The single-zero wheels lessen the house advantage as compared with the more ubiquitous double-zero wheels, but you won’t see me playing either version of roulette. I agree with Einstein who supposedly said, “You cannot beat a roulette table unless you steal money from it.” However, by using the RANDGEN subroutine, I can quickly simulate my losses for any betting scheme that I might be tempted to employ.

Share

Distinguished Researcher in Computational Statistics

Rick Wicklin, PhD, is a distinguished researcher in computational statistics at SAS and is a principal developer of SAS/IML software. His areas of expertise include computational statistics, simulation, statistical graphics, and modern methods in statistical data analysis. Rick is author of the books Statistical Programming with SAS/IML Software and Simulating Data with SAS.