Mapping the random function

As described over here, the rand() function in C++ is a pseudo random generator that returns a number between 0 and RAND_MAX. This number is generated by an algorithm that returns a sequence of apparently non-related numbers each time it is called. This algorithm uses a seed to generate the series, which should be initialized to some distinctive value using srand.

RAND_MAX is a constant defined in <cstdlib>

But just how random is the rand() function. Its easy to find out by calling the function and comparing how often different values are returned. I do this graphically using OpenGL code to render the graph.

Using fraps, I recorded the variation of outputs from the rand() function.

The graph tends towards a straight line indicating that the more often you call the rand() function, the more even its distribution.


Blackjack is the most widely played casino banking game in the world. It involves a dealer and one or more players. Each player is dealt two cards and then has the option to take additional cards to bring the value of his hand to 21 or less.

A game of Blackjack with the hand 21 (Image credit: Wikipedia)
Blackjack has been the target of many high-profile advantage players especially card counters, which prompted casinos to take preventive measures such as the use of 7 to 8 decks and the installation of the “eye in the sky”.

The movie 21 is based on the real life story of MIT students who trained as advantage player and made millions from Vegas casinos.

Unfortunately, when I wrote the game, I wasn’t too familiar with the rules of blackjack. The game play is somewhat lacking in experience. But, it was my first project involving texture loading, which was a big step forward.


Blackjack Screenshot

Download the game

Download the source

View the help file