summaryrefslogtreecommitdiff
path: root/osframework/source/SexyAppFramework/MTRand.h
blob: d01aa81bc0daaae43bdfe9062c53afb99b6e9fc2 (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef __MTRAND_H__
#define __MTRAND_H__

#include <string>

namespace Sexy
{

#define MTRAND_N 624

class MTRand
{
	unsigned long mt[MTRAND_N]; /* the array for the state vector  */
	int mti;

public:
	MTRand(const std::string& theSerialData);
	MTRand(unsigned long seed);
	MTRand();

	void SRand(const std::string& theSerialData);
	void SRand(unsigned long seed);
	unsigned long NextNoAssert();
	unsigned long Next();
	unsigned long NextNoAssert(unsigned long range);
	unsigned long Next(unsigned long range);
	float NextNoAssert(float range);
	float Next( float range );

	std::string Serialize();

	static void SetRandAllowed(bool allowed);
};

struct MTAutoDisallowRand
{
	MTAutoDisallowRand() { MTRand::SetRandAllowed(false); }
	~MTAutoDisallowRand() { MTRand::SetRandAllowed(true); }
};

}

#endif //__MTRAND_H__