[Assorted-commits] SF.net SVN: assorted: [475] cpp-commons/trunk/src/commons/rand.h
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-02-21 11:19:25
|
Revision: 475 http://assorted.svn.sourceforge.net/assorted/?rev=475&view=rev Author: yangzhang Date: 2008-02-21 02:47:39 -0800 (Thu, 21 Feb 2008) Log Message: ----------- added rng from rtm's code Added Paths: ----------- cpp-commons/trunk/src/commons/rand.h Added: cpp-commons/trunk/src/commons/rand.h =================================================================== --- cpp-commons/trunk/src/commons/rand.h (rev 0) +++ cpp-commons/trunk/src/commons/rand.h 2008-02-21 10:47:39 UTC (rev 475) @@ -0,0 +1,21 @@ +#ifndef COMMONS_RAND_H_ +#define COMMONS_RAND_H_ + +namespace commons +{ + /** + * TODO: Identify and rename this RNG. + */ + class posix_rand { + private: + unsigned long randx; + public: + posix_rand(long s = 0) { randx = s; } + void seed(long s) { randx = s; } + long abs(long x) { return x & 0x7fffffff; } + long draw() { return randx = randx * 1103515245 + 12345; } + long operator()() { return abs(draw()); } + }; +} + +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |