CL_Random ========= Random values can be extremly valuable in game development, be it for testing, random level generation, initial positions for monsters or whatever. However srand()/rand() have several limitiations which make them not well suited in general: - bad distribution, the standard method of limiting the range via rand()%max_rand causes 'bad' random values - non portable, different OSs might implement rand() different, which would make it unusable in networking games where one relies on reproducable random number values - no direct support for float - only one seed is allowed, but under different circumstances it might be usefull to have numerous independed streams of random values Thus I propose to add a CL_Random class to clanlib which servers the following purpose: - generation of streams of 'good' random values - generation of float and integer numbers with a given range - generation of portable random numbers, the same seed should on all OSs produce the same sequence of random values class CL_Random { public: /** Init the random generator with CL_System::get_time() */ CL_Random(); /** Init the random number generator with the given seed */ CL_Random(cl_uint32 seed); /** Return the seed that was used to create this object */ cl_uint32 get_seed(); /** Set a new seed value */ void reseed(cl_uint32 seed); /** Return a random value between between 0 and CL_Random::MAX_RAND */ cl_uint32 rand(); /** Return a random value in the range of [0, 1.0f] */ cl_uint32 rand(int range); /** Return a random value in the range of [0, range] */ cl_uint32 rand(int start, int stop); /** Return a random value in the range of [0, 1.0f] */ float frand(); /** Return a random value in the range of [0, range] */ float frand(float range); /** Return a random value in the range of [start, stop] */ float frand(float start, float stop); }; Todo: ===== - support for gausian distribution and other kinds distributions - probally additional support for real random values (/dev/random on linux) # EOF #