aboutsummaryrefslogtreecommitdiff
path: root/src/stable/randombase.h
blob: d33bb998cdd79096b255f100f3a41f4ec868a2c9 (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
/*
 * Copyright (C) 2007-2012 Xagasoft, All rights reserved.
 *
 * This file is part of the libbu++ library and is released under the
 * terms of the license contained in the file LICENSE.
 */
#ifndef BU_RANDOM_BASE_H
#define BU_RANDOM_BASE_H

#include <stdint.h>

namespace Bu
{
	class RandomBase
	{
	public:
		RandomBase();
		virtual ~RandomBase();

		virtual void seed( int32_t iSeed )=0;
		virtual int32_t rand()=0;
		virtual inline int32_t rand( int32_t iMax ) {
			return rand( 0, iMax );
		}
		virtual inline int32_t rand( int32_t iMin, int32_t iMax ) {
			return iMin+(randNorm()*(iMax-iMin));
		}
		virtual inline double randNorm() {
			return (((uint32_t)rand())&0xfffffffeul)*0x1.00000001p-32;
//			return (((uint32_t)rand())&0xfffffffeul)/(double)(0xfffffffful);
		}
	};
};

#endif