blob: ed560e03d9730e71a43d6bfe406eadecf99aa695 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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);
}
};
|