--> Jim Robin wrote to All <--
JR>I've got this friend who is constructing a dice game using Visual
JR>C++ where one of the required elements is to simulate the throwing
JR>of a 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
JR>value - in the case of the dice example 1 - 6.
#include
#include
class Di {
private:
int currentState;
public:
Di() { srand((unsigned int) time(NULL)); currentState = 1; }
int throw() { currentState = (rand() % 6) + 1;
return currentState; }
int getState() { return currentState; }
};
Cliff Rhodes
cliff.rhodes@juge.com
X CMPQwk 1.42 1692 X"Great joys weep, great sorrows laugh." - Joseph Roux
--- Maximus/2 3.01
---------------
* Origin: COMM Port OS/2 juge.com 204.89.247.1 (281) 980-9671 (1:106/2000)
|