ETL
0.04.19
Main Page
Related Pages
Classes
Files
File List
File Members
ETL
_random.h
Go to the documentation of this file.
1
25
/* === S T A R T =========================================================== */
26
27
#ifndef __ETL__RANDOM_H
28
#define __ETL__RANDOM_H
29
30
/* === H E A D E R S ======================================================= */
31
32
/* === M A C R O S ========================================================= */
33
34
/* === C L A S S E S & S T R U C T S ======================================= */
35
36
_ETL_BEGIN_NAMESPACE
37
38
/*
39
class rand_source_xor
40
{
41
public:
42
typedef int seed_type;
43
typedef short value_type;
44
45
private:
46
short entropy_pool[256];
47
int pool_index;
48
49
public:
50
random()
51
{
52
seed(0);
53
mod=offset=0;
54
}
55
56
void seed(const seed_type &x)
57
{ pool_index=0; }
58
59
void add_entropy(value_type entropy)
60
{
61
int i;
62
for(i=0;i<POOL_SIZE;i++)
63
entropy^=(entropy_pool[i]^=entropy*i);
64
}
65
66
void add_entropy(const value_type *entropy, int size)
67
{
68
}
69
70
short get_short()
71
{
72
if(pool_index>POOL_SIZE)
73
pool_index=0;
74
if(mod)
75
return entropy_pool[pool_index++]%mod+offset;
76
return entropy_pool[pool_index++];
77
}
78
};
79
*/
80
81
template
<
class
T,
int
POOL_SIZE=256>
82
class
random
83
{
84
public
:
85
typedef
T
value_type
;
86
typedef
int
seed_type
;
87
88
private
:
89
value_type
entropy_pool
[POOL_SIZE];
90
int
pool_index
;
91
92
value_type
mod
,
offset
;
93
94
public
:
95
random
()
96
{
97
seed
(0);
98
mod
=
offset
=0;
99
}
100
101
void
seed
(
const
seed_type
&x __attribute__ ((unused)))
102
{
pool_index
=0; }
103
104
void
set_range
(
const
value_type
&
floor
,
const
value_type
&
ceil
)
105
{
mod
=ceil-
floor
;
offset
=
floor
; }
106
107
void
set_range
(
const
value_type
&
ceil
)
108
{
mod
=
ceil
; }
109
110
void
add_entropy
(
value_type
entropy)
111
{
112
int
i;
113
for
(i=0;i<POOL_SIZE;i++)
114
entropy^=(
entropy_pool
[i]^=entropy*i);
115
}
116
117
void
add_entropy
(
const
char
*entropy)
118
{
119
}
120
121
value_type
operator()
(
void
)
122
{
123
if
(
pool_index
>POOL_SIZE)
124
pool_index
=0;
125
if
(
mod
)
126
return
entropy_pool
[
pool_index
++]%
mod
+
offset
;
127
return
entropy_pool
[
pool_index
++];
128
}
129
};
130
131
/* === T Y P E D E F S ===================================================== */
132
133
_ETL_END_NAMESPACE
134
135
/* === E N D =============================================================== */
136
137
#endif
138
Generated on Mon Nov 16 2015 15:32:03 for ETL by
1.8.1.2