TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: JIM ROBIN
from: CLIFF RHODES
date: 1997-05-04 14:26:00
subject: Throw of dice

--> 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)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.