Many people are not only perplexed by the concept of random when using the RND() function, they also misunderstand the concept of random. Many system gamblers have lost their bankroll and gone broke because of this misunderstanding.
Las Vegas dice are manufactured to a tolerance less than .0001 of an inch. That's 1/10,000 of an inch! If you've ever watched an actual game in a legal casino (Las Vegas, Reno, Atlantic City, etc.), it's not unusual to see the "pit boss" take out a micrometer and "mike" the dice to insure they are within tolerance, i.e., no one has switched the dice and substituted "shaved dice" which will have a greater tendency to come up with a pre-selected face showing.
You might also see a pit employee hold a die (singular of dice) by diagonally opposing corners and spin the die between his fingers. This is to check for "weighted" dice, where a cheat expects the face opposite weights to be exposed more often than the weighted side. Then, too, there are "mis-spots," but we don't want to discuss all the inside secrets of cheating, do we?
Computer programmers know the possibility of any single permutation of two dice is 1 in 36. That is, "snake-eyes" can only be rolled by a combination of two 1's. Since there are six sides for each die, the probability of snake-eyes becomes 1/(6*6). The same holds true for any pair rolled. Other numbers can be rolled by two or more combinations.
Just because there are 36 possible combinations does not mean "Snake-eyes just rolled, now the dice have to roll all the remaining combinations before snake-eyes comes up again!" It's not unusual for any combination to repeat during consecutive rolls, or more often that probabilities would predict.
So, when writing your dice, roulette, black-jack, or cointoss routine, just how random is random?
The following snippet is a graphic display of a roulette wheel over the course of 5,000 spins (called 'decisions' in casino parlance). Remember, an American roulette wheel will have 36 numbers plus 0 and 00, for a total of 38 possible decisions; a European roulette wheel has 36 numbers and 0 only. Any player can bet on 0 or 00 if they so choose, or any combination of multiple numbers. (The croupier will ensure you are properly paid, should you win... so you won't have to know all the payoff combinations.)
'A VISUAL display of the RND() function
'by Welopez, 090506
DIM row(38) 'sets up an array for 38 "y" values
NOMAINWIN
WindowWidth=400
WindowHeight=300
UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
UpperLeftY=INT((DisplayHeight-WindowHeight)/2)
BUTTON #demo.btn1, "Start", [begin], LL, 75, 0, 50, 30
BUTTON #demo.btn2, "Quit", [quit], LL, 275, 0, 50, 30
GRAPHICBOX #demo.gb1, 10, 10, 375, 200
OPEN "RANDOM Histogram" FOR WINDOW AS #demo
PRINT "trapclose [quit]"
PRINT #demo.gb1, "COLOR blue"
PRINT #demo.gb1, "SIZE 4"
PRINT #demo.gb1, "DOWN"
WAIT
[begin]
FOR k=1 to 5000
column=INT(RND(0)*38)+1
row(column)=row(column)+1
PRINT #demo.gb1, "SET "; (column*10)-3;" ";(200-(row(column)))
'TIMER 1, [resume]
'WAIT
'[resume]
'TIMER 0
NEXT k
PRINT #demo.gb1, "PLACE 130 190"
PRINT #demo.gb1, "\Demo complete."
WAIT
[quit]
CLOSE #demo
END
The TIMER value in this routine is only 1 ms, but in 5,000 decisions, that adds up to five seconds. Remove the apostrophe which rems out the TIMER if you want to see the display build up more slowly.
Every time the wheel is spun and the ball drops, the RND() function picks one of 38 possibilities and the number of times that number has come up is accumulated in row() array. The graphic box shows 38 columns, representing each of the possible decisions. The length of the bar represents the number of times that number appeared, with numbers 1 thru 36, 0 and 00, represented left to right.
If random values were uniform, every bar would be the same length. Fortunately, random values are not uniform, they are random, meaning each decision has an equal chance of coming up the next time the wheel is spun. Over 5,000 spins, statistically the length of each bar will be nearly equal to the rest, but it is highly unlikely all of them will be equal. When we spin 50,000, 500,000, or 5,000,000 times, the length of the bars will be more nearly equal, but rarely exactly equal. This is called the "probability of large numbers."
The house always wins, not because the games are rigged, but because the payoffs are set by a pre-determined formula. In roulette, for example, a $1 bet on a single number wins $35, but the probability of that number coming up is 38 to 1. In other words, you win, but the house pays you only 92.1% of what you risked. In dice, if you bet $1 on 12, you win $30, but the house pays you only 83.3% of what you risked. You know the odds before you bet (or you should!), and you've accepted the risk you are taking. The house does not need to cheat you to win in the long run, and casinos will be there day after day, month after month, year after year, winning money from an endless supply of tourists, even while they are paying off the winners!
The purpose of this graphic demo is to show, while deviation from the norm is expected, if one of the bars is ALWAYS significantly more or less than the others, somebody has rigged your roulette wheel, or the programmer has pulled a fast one on you!
My roulette wheel has not been tampered with! Honest