diff options
author | Chris Xiong <chirs241097@gmail.com> | 2015-10-06 21:28:40 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2015-10-06 21:28:40 +0800 |
commit | 038b31f0158a0018dbf2eceb71026cc4e665faa9 (patch) | |
tree | a373ddab7bc162e477e28a780b0d729660ff8634 /include/smrandom.hpp | |
parent | a8077292d5d9118866f7358c11a90c855e1b1b02 (diff) | |
download | SMELT-038b31f0158a0018dbf2eceb71026cc4e665faa9.tar.xz |
Add the SMELT files...
Please, do not laugh too loudly.
Diffstat (limited to 'include/smrandom.hpp')
-rw-r--r-- | include/smrandom.hpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/include/smrandom.hpp b/include/smrandom.hpp new file mode 100644 index 0000000..ed560e0 --- /dev/null +++ b/include/smrandom.hpp @@ -0,0 +1,29 @@ +// -*- C++ -*- +/* + * Simple MultimEdia LiTerator(SMELT) + * by Chris Xiong 2015 + * Random engine header & implementation + * + * WARNING: This library is in development and interfaces would be very + * unstable. + * + */ +class smRandomEngine +{ +private: + unsigned int cseed; +public: + void setSeed(unsigned int seed){cseed=seed;} + int nextInt(int min,int max) + { + if (min>max){int t=min;min=max;max=t;} + cseed*=214013;cseed+=2531011; + return min+(cseed^cseed>>15)%(max-min+1); + } + double nextDouble(double min,double max) + { + if (min>max){double t=min;min=max;max=t;} + cseed*=214013;cseed+=2531011; + return min+(cseed>>16)*(1.0f/65535.0f)*(max-min); + } +}; |