synfig-core
1.0.3
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
src
synfig
quick_rng.h
Go to the documentation of this file.
1
/* === S Y N F I G ========================================================= */
22
/* ========================================================================= */
23
24
/* === S T A R T =========================================================== */
25
26
#ifndef __SYNFIG_QUICK_RNG_H
27
#define __SYNFIG_QUICK_RNG_H
28
29
/* === H E A D E R S ======================================================= */
30
31
#include <stdint.h>
32
33
/* === M A C R O S ========================================================= */
34
35
/* === T Y P E D E F S ===================================================== */
36
37
/* === C L A S S E S & S T R U C T S ======================================= */
38
39
// A fast 32-bit linear congruential random number generator
40
class
quick_rng
41
{
42
uint32_t
next;
43
public
:
44
quick_rng
(
uint32_t
seed=0):next(seed) { }
45
46
void
set_seed
(
uint32_t
x)
47
{
48
next=x;
49
}
50
51
uint32_t
i32
()
52
{
53
static
const
uint32_t
a(1664525);
54
static
const
uint32_t
c(1013904223);
55
56
return
next=next*a+c;
57
}
58
59
uint32_t
i16
()
60
{
61
return
i32
()>>16;
62
}
63
64
float
f
()
65
{
66
static
const
float
m(
int
(65535));
67
68
return
float(
i16
())/m;
69
}
70
71
uint32_t
operator()
(
const
uint32_t
& m)
72
{
73
if
(m==65536)
74
return
i16
();
75
else
76
if
(m<=65536)
77
return
i16
()%m;
78
else
79
return
i32
()%m;
80
}
81
};
82
83
/* === E N D =============================================================== */
84
85
#endif
Generated on Mon Nov 16 2015 15:33:48 for synfig-core by
1.8.1.2