The main mathematical topic in this episode are using math to determine strategies for winning against casinos at blackjack. Along the way, a discussion of generating psuedorandom numbers comes up.

Blackjack (also called 21) is a card game which is frequently
played in casinos and is the
central theme of this episode. Since the rules in casinos might be slightly
different than the rules you may have played by in the past, we'll go
through the (slightly simplified) rules first. The goal of the game is
to get cards that add up
to 21 or as close as possible without *busting*, which means going over
21. Cards with numbers are counted for their number values, face cards (Jack,
Queen, King) are 10 points, and an Ace is either 1 or 11. Each player is only
playing against the dealer (who represents the casino) and not against the
other players. To begin the game, each player puts in a bet and then
the dealer gives each of the players two
cards, face up, and gives herself 1 card face up and another card face down,
as in this example (the dealer is at the top).

Then the player on the dealers left acts. If he is happy with his cards, he
*stays*, or if he would like another card, he *hits*. This continues
until he stays or until he busts. Then the rest of the players do the same
thing in turn. Once all the players have had their turn, then the dealer has
her turn. However, the dealer never has the choice of whether to hit or stay,
she must follow predetermined rules. If her hand sums to 16 or less, she must
hit, and if it sums to 17 or more, she must stay.

- Let's say you're the dealer and you have a 10 and a 6. You must draw a card (but you won't have to draw another one). What are the odds that you bust? (To make it easier assume that the odds of drawing all the different ranks of cards are the same. That is, you are as likely to draw a 6 as you are to draw a 7 or 10 or Ace, etc.)
- What if the dealer has cards that sum to 15? What is the probability that she busts when she draws?
- What if the dealer has cards that sum to 14? What is the probablility that she busts? (Hint: this is different than the last two, because if she draws a 2, then her total is 16 and she must draw again.)

Since the actual analysis of optimal play is very complex,
either a computer or a whole lot of time is needed to figure it out. Casinos
before the 1960's didn't realize this, and
some of them unintentionally used rule sets there were advantageous for
players who were playing optimally. This changed when the groundbreaking book
"Beat the Dealer: A Winning Strategy for the Game of Twenty-One" by
Edward Thorp was published in 1966.

- Repeat activity 2 with the assumption that there are no cards of value 10 nor any aces in the deck, but that the probability of drawing any of the other cards is the same.
- Repeat activity 2 with the assumption that there are no aces and no cards of value 2-7 in the deck, but that the probability of drawing any of the other cards is the same.

A second way to generate "random" numbers is to use a computer
algorithm to produce numbers that satisfy many of the tests that true random
numbers would. Since output from a computer is never random, but is instead
completely determined, numbers generated in this way are called
*psuedo-random* numbers. One of the simplest ways of doing this is called
a *linear congruential generator*. This method produces a series of
numbers labelled f(0), f(1), f(2), etc. The first number, f(0), is called
the *seed* because it has to be generated from an outside source and
it begins the sequence. Then given a number in the sequence f(n), the next
number in the sequence satisfies the equation

Here A,B, and M are fixed numbers selected beforehand. Also, the symbol
(mod *M*) means "take the remainder after dividing by *M*".
For example, 27 (mod 10) = 7, 27 (mod 3) = 0, and 27 (mod 4) = 3.

There is a famous example of a very popular linear
congruential generator called
RANDU that has been used since the 1960s. The
constants A,B,M were chosen very poorly, and as a result the numbers it
generated were not very random at all. As a result, many simulations done with
this generator are now looked upon with suspiscion.

- Let's try A = 2, B = 4, M = 10. Write down the first 8 numbers generated.
- Now try A = 3, B = 7, M = 10. Write down the first 8 numbers generated.
- Which of these two choices do you think is better? Why?