tlds
Transactional Operations for Linked Data Structures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
random.h
Go to the documentation of this file.
1 /* =============================================================================
2  *
3  * random.h
4  *
5  * =============================================================================
6  *
7  * Copyright (C) Stanford University, 2006. All Rights Reserved.
8  * Author: Chi Cao Minh
9  *
10  * =============================================================================
11  *
12  * For the license of bayes/sort.h and bayes/sort.c, please see the header
13  * of the files.
14  *
15  * ------------------------------------------------------------------------
16  *
17  * For the license of kmeans, please see kmeans/LICENSE.kmeans
18  *
19  * ------------------------------------------------------------------------
20  *
21  * For the license of ssca2, please see ssca2/COPYRIGHT
22  *
23  * ------------------------------------------------------------------------
24  *
25  * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the
26  * header of the files.
27  *
28  * ------------------------------------------------------------------------
29  *
30  * For the license of lib/rbtree.h and lib/rbtree.c, please see
31  * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree
32  *
33  * ------------------------------------------------------------------------
34  *
35  * Unless otherwise noted, the following license applies to STAMP files:
36  *
37  * Copyright (c) 2007, Stanford University
38  * All rights reserved.
39  *
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions are
42  * met:
43  *
44  * * Redistributions of source code must retain the above copyright
45  * notice, this list of conditions and the following disclaimer.
46  *
47  * * Redistributions in binary form must reproduce the above copyright
48  * notice, this list of conditions and the following disclaimer in
49  * the documentation and/or other materials provided with the
50  * distribution.
51  *
52  * * Neither the name of Stanford University nor the names of its
53  * contributors may be used to endorse or promote products derived
54  * from this software without specific prior written permission.
55  *
56  * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY
57  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
59  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE
60  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
61  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
62  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
63  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
64  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
66  * THE POSSIBILITY OF SUCH DAMAGE.
67  *
68  * =============================================================================
69  */
70 
71 
72 #ifndef RANDOM_H
73 #define RANDOM_H 1
74 
75 
76 #include "mt19937ar.h"
77 
78 
79 #ifdef __cplusplus
80 extern "C" {
81 #endif
82 
83 
84 #define RANDOM_DEFAULT_SEED (0)
85 
86 typedef struct random {
87  unsigned long (*rand)(unsigned long*, unsigned long*);
88  unsigned long mt[N];
89  unsigned long mti;
90 } random_t;
91 
92 
93 /* =============================================================================
94  * random_alloc
95  * -- allocates and initialize datastructure
96  * -- Returns NULL if failure
97  * =============================================================================
98  */
99 random_t*
100 random_alloc ();
101 
102 
103 /* =============================================================================
104  * Prandom_alloc
105  * -- allocates and initialize datastructure
106  * -- Returns NULL if failure
107  * =============================================================================
108  */
109 random_t*
110 Prandom_alloc ();
111 
112 
113 /* =============================================================================
114  * random_free
115  * =============================================================================
116  */
117 void
118 random_free (random_t* randomPtr);
119 
120 
121 /* =============================================================================
122  * Prandom_free
123  * =============================================================================
124  */
125 void
126 Prandom_free (random_t* randomPtr);
127 
128 
129 /* =============================================================================
130  * random_seed
131  * =============================================================================
132  */
133 void
134 random_seed (random_t* randomPtr, unsigned long seed);
135 
136 
137 /* =============================================================================
138  * random_generate
139  * =============================================================================
140  */
141 unsigned long
142 random_generate (random_t* randomPtr);
143 
144 
145 #define PRANDOM_ALLOC() Prandom_alloc()
146 #define PRANDOM_FREE(r) Prandom_free(r)
147 #define PRANDOM_SEED(r, s) random_seed(r, s)
148 #define PRANDOM_GENERATE(r) random_generate(r)
149 
150 
151 #ifdef __cplusplus
152 }
153 #endif
154 
155 
156 #endif /* RANDOM_H */
157 
158 
159 /* =============================================================================
160  *
161  * End of random.h
162  *
163  * =============================================================================
164  */
random_t * Prandom_alloc()
Definition: random.c:102
void random_seed(random_t *randomPtr, unsigned long seed)
Definition: random.c:141
void random_free(random_t *randomPtr)
Definition: random.c:119
unsigned long(* rand)(unsigned long *, unsigned long *)
Definition: random.h:87
static int seed
Definition: mesh.cpp:40
struct random random_t
unsigned long mt[N]
Definition: random.h:88
#define N
Definition: mt19937ar.h:135
unsigned long mti
Definition: random.h:89
unsigned long random_generate(random_t *randomPtr)
Definition: random.c:152
Definition: random.h:86
random_t * random_alloc()
Definition: random.c:84
void Prandom_free(random_t *randomPtr)
Definition: random.c:130