//===========================================================================// // File: random.cc // // Project: MUNGA Brick: Math Library // // Contents: Interface specification for the random number generator // //---------------------------------------------------------------------------// // Date Who Modification // // -------- --- ---------------------------------------------------------- // // 11/20/93 JMA Initial coding. // //---------------------------------------------------------------------------// // Copyright (C) 1993-1995, Virtual World Entertainment, Inc. // // All Rights reserved worldwide // // This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL // //===========================================================================// #if !defined(RANDOM_HPP) # define RANDOM_HPP # if !defined(SCALAR_HPP) # include # endif //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Random ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class RandomGenerator SIGNATURED { private: static int Numbers[250]; // the random number table static int Index; // the current entry within the table static void Init(); static int GetRandomInt(); public: RandomGenerator() {if (Index == -1) Init();} // //------------------------ // Random number functions //------------------------ // int GetInt() // returns 0 .. RAND_MAX {return GetRandomInt();} operator Scalar(); // returns 0.0f <= x < 1.0f int // returns 0 .. Range-1 operator ()(int Range); static Logical TestClass(); }; extern RandomGenerator Random; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Die ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class Die SIGNATURED { private: int highestRandom, // the highest random number giving a uniform dist. dieSides; // the number of sides on the die (starting from 1) public: Die(int sides); operator int(); // returns 1 .. dieSides }; #endif