File: Random.h

package info (click to toggle)
freespace2 24.0.2%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: trixie
  • size: 43,188 kB
  • sloc: cpp: 583,107; ansic: 21,729; python: 1,174; sh: 464; makefile: 248; xml: 181
file content (31 lines) | stat: -rw-r--r-- 765 bytes parent folder | download | duplicates (4)
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
#pragma once

namespace util {

class Random {
public:
	static constexpr int MAX_VALUE = 0x7fffffff;
	static constexpr int HALF_MAX_VALUE = MAX_VALUE / 2;
	static constexpr float INV_F_MAX_VALUE = 1.0f / static_cast<float>(MAX_VALUE);

	// seed(1) will result in RNG using its default seed
	static void seed(unsigned int val);

	// return a value in [0, MAX_VALUE]
	static int next(); // uniformly between 0 and MAX_VALUE

	// return a value in [0, modulus-1]
	static int next(int modulus);

	// return a value in [low, high]
	static int next(int low, int high);

	// return true/false with equal probability
	static bool flip_coin();

	// jump ahead in the RNG sequence
	static void advance(unsigned long long distance);
private:
	Random();
};
} // namespace util