Panda3D
Loading...
Searching...
No Matches
randomizer.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file randomizer.h
10 * @author drose
11 * @date 2007-01-18
12 */
13
14#ifndef RANDOMIZER_H
15#define RANDOMIZER_H
16
17#include "pandabase.h"
18#include "mersenne.h"
19
20#include <time.h>
21#include <math.h>
22
23/**
24 * A handy class to return random numbers.
25 */
26class EXPCL_PANDA_MATHUTIL Randomizer {
27PUBLISHED:
28 INLINE explicit Randomizer(unsigned long seed = 0);
29 INLINE Randomizer(const Randomizer &copy);
30 INLINE void operator = (const Randomizer &copy);
31
32 INLINE int random_int(int range);
33 INLINE double random_real(double range);
34 INLINE double random_real_unit();
35
36 INLINE static unsigned long get_next_seed();
37 INLINE unsigned long get_seed();
38
39private:
40 Mersenne _mersenne;
41 static Mersenne _next_seed;
42 static bool _got_first_seed;
43};
44
45#include "randomizer.I"
46
47#endif
double random_real_unit()
Returns a random double in the range [-0.5, 0.5).
Definition randomizer.I:61
Randomizer(unsigned long seed=0)
If seed is nonzero, it is used to define the tables; if it is zero a random seed is generated.
Definition randomizer.I:19
unsigned long get_seed()
Returns a unique seed value based on the seed value passed to this Randomizer object (and on its curr...
Definition randomizer.I:82
double random_real(double range)
Returns a random double in the range [0, range).
Definition randomizer.I:53
static unsigned long get_next_seed()
Returns a random seed value for the next global Randomizer object.
Definition randomizer.I:69
int random_int(int range)
Returns a random integer in the range [0, range).
Definition randomizer.I:45
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.