aboutsummaryrefslogtreecommitdiff
path: root/include/smrandom.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/smrandom.hpp')
-rw-r--r--include/smrandom.hpp29
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);
+ }
+};