For random numbers you use the rand() and srand() functions. You need the <cstdlib> library header to use them. Basically to get a random number between 0 and RAND_MAX (where RAND_MAX is at least 32767) enter

x = rand();

where x is an integer.

The srand function allows you to seed the random number generator (this is crucial otherwise your random numbers will always be the same). This works like this

srand( y );

again y is an integer.

Generally you see people calling the srand function with the time function. This gives the appreance of randomness because very few people in history could percieve the link between the time and the numbers generated. To use the time function you must add the <ctime> library header. It works like this.

srand ( time( NULL ) );

Be sure to set this at least once in your program but you can use it several times depending on how your program is to work. If you are doing some kind of modelling then each time the model runs a new seeding is probably a good idea. Once you've seeded the generator what you actually get is a series of predetermined but apparently random numbers and the rand() function just outputs them one at a time.

One last thing. To generate a number between a certain range use this equation

x = m + rand() % n;

where the range is m < (m + n - 1). Hope this helps.

Last time I checked 'C++ programming tutorials' gives 2m results, you can't have tried them all

. One resource I picked up which is quite complete is thinking in C++ volumes 1 and 2, you can pick them up on PDF for free.