While gazing into my crystal ball, I saw a message from Jim Robin to All
JR> I've got this friend who is constructing a dice game using Visual C++
JR> where one of the required elements is to simulate the throwing of a
JR> dice.
JR> To cut a long story short does anyone know of an algorithm that can
JR> generate numbers between a lower bound value and an upper bound value
JR> - in the case of the dice example 1 - 6.
Your compiler should have a function called random() or something similar.
(written for Borland Turbo C++)
#include
#include
main()
{
randomize(); // Resets the random number generator seed using current time
int dice_roll = random(6) + 1; // Random(int mod) generates a random value
// between 0 and mod-1
}
--- FMail 1.02
---------------
* Origin: The misty isles of Stonegaia (1:159/600)
|