Brahe - a heterogenous collection of mathematical tools

Main Index
Home Page

Created by Scott Robert Ladd


prng.h
Go to the documentation of this file.
1/*
2 Brahe is a heterogenous collection of mathematical tools, written in Standard C.
3
4 Copyright 2011 Scott Robert Ladd. All rights reserved.
5
6 Brahe is user-supported open source software. Its continued development is dependent
7 on financial support from the community. You can provide funding by visiting the Brahe
8 website at:
9
10 http://www.coyotegulch.com
11
12 You may license Brahe in one of two fashions:
13
14 1) Simplified BSD License (FreeBSD License)
15
16 Redistribution and use in source and binary forms, with or without modification, are
17 permitted provided that the following conditions are met:
18
19 1. Redistributions of source code must retain the above copyright notice, this list of
20 conditions and the following disclaimer.
21
22 2. Redistributions in binary form must reproduce the above copyright notice, this list
23 of conditions and the following disclaimer in the documentation and/or other materials
24 provided with the distribution.
25
26 THIS SOFTWARE IS PROVIDED BY SCOTT ROBERT LADD ``AS IS'' AND ANY EXPRESS OR IMPLIED
27 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
28 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SCOTT ROBERT LADD OR
29 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
32 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
36 The views and conclusions contained in the software and documentation are those of the
37 authors and should not be interpreted as representing official policies, either expressed
38 or implied, of Scott Robert Ladd.
39
40 2) Closed-Source Proprietary License
41
42 If your project is a closed-source or proprietary project, the Simplified BSD License may
43 not be appropriate or desirable. In such cases, contact the Brahe copyright holder to
44 arrange your purchase of an appropriate license.
45
46 The author can be contacted at:
47
48 scott.ladd@coyotegulch.com
49 scott.ladd@gmail.com
50 http:www.coyotegulch.com
51*/
52
53#if !defined(LIBBRAHE_PRNG_H)
54#define LIBBRAHE_PRNG_H
55
56#include "mathtools.h"
57
58#if defined(__cplusplus)
59extern "C" {
60#endif
61
76
78typedef struct
79{
80 brahe_prng_type_t m_type; // the algorithm we're using
81 uint32_t m_seed; // "seed" that defines the sequence
82 void * m_data1; // array or table
83 void * m_data2; // additional array or table
84 size_t m_i; // only used by some algorithms
85 size_t m_a; // only used by some algorithms
86 size_t m_b; // only used by some algorithms
87 size_t m_c; // only used by some algorithms
89
90static uint32_t BRAHE_UNKNOWN_SEED = 0;
91
93
100bool brahe_prng_init(brahe_prng_state_t * prng_state, const brahe_prng_type_t type, const uint32_t seed);
101
103
109
111
116uint32_t brahe_prng_next(brahe_prng_state_t * prng_state);
117
119
126uint32_t brahe_prng_range(brahe_prng_state_t * prng_state, const uint32_t lo, const uint32_t hi);
127
129
135size_t brahe_prng_index(brahe_prng_state_t * prng_state, const size_t length);
136
138
146
148
156
158
166
168
176
177#if defined(__cplusplus)
178}
179#endif
180
181#endif
size_t brahe_prng_index(brahe_prng_state_t *prng_state, const size_t length)
Get the next random value as a size_t index.
static uint32_t BRAHE_UNKNOWN_SEED
Definition prng.h:90
double brahe_prng_real2(brahe_prng_state_t *prng_state)
Get the next number in the range [0,1)
uint32_t brahe_prng_range(brahe_prng_state_t *prng_state, const uint32_t lo, const uint32_t hi)
Get the next integer in the range [lo,hi].
bool brahe_prng_init(brahe_prng_state_t *prng_state, const brahe_prng_type_t type, const uint32_t seed)
Initialize a psuedo-random number generator (PRNG)
void brahe_prng_free(brahe_prng_state_t *prng_state)
Free resources used by PRNG.
double brahe_prng_real1(brahe_prng_state_t *prng_state)
Get the next number in the range [0,1].
brahe_prng_type_t
Defines types of prngs.
Definition prng.h:64
@ BRAHE_PRNG_ISAAC
Indirect, Shift, Accumulate, Add, and Count (Jenkins)
Definition prng.h:74
@ BRAHE_PRNG_MARSENNE_TWISTER
Marsenne Twister (Matsumoto & Nishimura)
Definition prng.h:66
@ BRAHE_PRNG_MWC1038
MWC1038 (Marsaglia)
Definition prng.h:72
@ BRAHE_PRNG_CMWC4096
CMWC4096 (Marsaglia)
Definition prng.h:70
@ BRAHE_PRNG_KISS
Keep is Simple, Stupid (Marsaglia)
Definition prng.h:68
uint32_t brahe_prng_next(brahe_prng_state_t *prng_state)
Get the next integer.
double brahe_prng_real53(brahe_prng_state_t *prng_state)
Get the next number in the range [0,1)
double brahe_prng_real3(brahe_prng_state_t *prng_state)
Get the next number in the range (0,1)
Contains state variables for a PRNG.
Definition prng.h:79
void * m_data2
Definition prng.h:83
size_t m_b
Definition prng.h:86
void * m_data1
Definition prng.h:82
size_t m_i
Definition prng.h:84
size_t m_a
Definition prng.h:85
size_t m_c
Definition prng.h:87
brahe_prng_type_t m_type
Definition prng.h:80
uint32_t m_seed
Definition prng.h:81

© 2011 Scott Robert Ladd. All rights reserved.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.