/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
152 by Gustav Hartvigsson
* Made SRandom compile
1
#pragma once
2
/*
3
Copyright (c) 2013-2017 Gustav Hartvigsson
4
5
Permission is hereby granted, free of charge, to any person obtaining a copy
6
of this software and associated documentation files (the "Software"), to deal
7
in the Software without restriction, including without limitation the rights
8
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
copies of the Software, and to permit persons to whom the Software is
10
furnished to do so, subject to the following conditions:
11
12
The above copyright notice and this permission notice shall be included in
13
all copies or substantial portions of the Software.
14
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
THE SOFTWARE.
22
 */
23
24
/*
25
Adaptation of
26
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/C-LANG/mt19937-64.c
27
with the following license:
28
29
Copyright (C) 2004, Makoto Matsumoto and Takuji Nishimura,
30
All rights reserved.                          
31
32
Redistribution and use in source and binary forms, with or without
33
modification, are permitted provided that the following conditions
34
are met:
35
36
 1. Redistributions of source code must retain the above copyright
37
    notice, this list of conditions and the following disclaimer.
38
39
 2. Redistributions in binary form must reproduce the above copyright
40
    notice, this list of conditions and the following disclaimer in the
41
    documentation and/or other materials provided with the distribution.
42
43
 3. The names of its contributors may not be used to endorse or promote 
44
    products derived from this software without specific prior written 
45
    permission.
46
47
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
48
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
49
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
50
A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
51
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
52
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
53
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
54
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
55
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
56
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
57
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58
*/
59
60
/**
61
 * @file
62
 */
63
64
65
#include "defs.h"
66
67
S_BEGIN_DECLS
68
69
/**
70
 * @defgroup Random Random
71
 * @addtogroup Random
72
 * @{
73
 */
74
75
/**
76
 * An opaque data type that represents the a random value generator.
77
 *
78
 * SRandom is the perfered psuedo random number generator in libssts.
79
 * It is object oriented and as such can be very versitile.
80
 *
81
 * What it uses internally (right now) is an adapted version of mt19937-64 by
82
 * Makoto Matsumoto and Takuji Nishimura. (see:
83
 * http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/C-LANG/mt19937-64.c)
84
 *
85
 * It will genrate a 64 bit random number. To use this 
86
 */
87
typedef struct SRandom SRandom;
88
89
S_EXPORTED
90
SRandom *
91
s_random_new ();
92
93
S_EXPORTED
94
void
95
s_random_free (SRandom * self);
96
97
S_EXPORTED
98
SRandom *
99
s_random_new_with_seed (sulong seed);
100
101
S_EXPORTED
102
void
103
s_random_reseed (SRandom * self, sulong seed);
104
105
S_EXPORTED
106
sulong
107
s_random_next (SRandom * self);
108
109
S_EXPORTED
110
sulong
111
s_random_current (SRandom * self);
112
113
/**
114
 * Generate a random number between @f$0@f$ and @f$2^{63}-1@f$
115
 */
116
S_EXPORTED
117
slong
118
s_random_next_long (SRandom * self);
119
120
/**
121
 * Generate a random real number in the interval @f$[0 ... 1]@f$.
122
 */
123
S_EXPORTED
124
sdouble
125
s_random_next_real (SRandom * self);
126
127
/**
128
 * Get the current random as a number between @f$0@f$ and @f$2^{63}-1@f$
129
 */
130
S_EXPORTED
131
slong
132
s_random_current_long (SRandom * self);
133
134
/**
135
 * Get the current random as a real number in the interval @f$[0 ... 1]@f$.
136
 */
137
S_EXPORTED
138
sdouble
139
s_random_current_real (SRandom * self);
140
141
#if 0
142
/* Get entropy from the system, how this is done under the hood is platform
143
 * specific.
144
 *
145
 * @note Do not abuse this as a source of random numbers, that will deplete the
146
 * entropy pool, which is not desirable.
147
 */
148
S_EXPORTED
149
slong
150
s_random_get_entropy ();
151
#endif
152
153
/**
154
 * @}
155
 */
156
157
S_END_DECLS