| 1 | /** 
 | 
|---|
| 2 |  * @file dSFMT.h 
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  * @brief double precision SIMD oriented Fast Mersenne Twister(dSFMT)
 | 
|---|
| 5 |  * pseudorandom number generator based on IEEE 754 format.
 | 
|---|
| 6 |  *
 | 
|---|
| 7 |  * @author Mutsuo Saito (Hiroshima University)
 | 
|---|
| 8 |  * @author Makoto Matsumoto (Hiroshima University)
 | 
|---|
| 9 |  *
 | 
|---|
| 10 |  * Copyright (C) 2007, 2008 Mutsuo Saito, Makoto Matsumoto and
 | 
|---|
| 11 |  * Hiroshima University. All rights reserved.
 | 
|---|
| 12 |  *
 | 
|---|
| 13 |  * The new BSD License is applied to this software.
 | 
|---|
| 14 |  * see LICENSE.txt
 | 
|---|
| 15 |  *
 | 
|---|
| 16 |  * @note We assume that your system has inttypes.h.  If your system
 | 
|---|
| 17 |  * doesn't have inttypes.h, you have to typedef uint32_t and uint64_t,
 | 
|---|
| 18 |  * and you have to define PRIu64 and PRIx64 in this file as follows:
 | 
|---|
| 19 |  * @verbatim
 | 
|---|
| 20 |  typedef unsigned int uint32_t
 | 
|---|
| 21 |  typedef unsigned long long uint64_t  
 | 
|---|
| 22 |  #define PRIu64 "llu"
 | 
|---|
| 23 |  #define PRIx64 "llx"
 | 
|---|
| 24 | @endverbatim
 | 
|---|
| 25 |  * uint32_t must be exactly 32-bit unsigned integer type (no more, no
 | 
|---|
| 26 |  * less), and uint64_t must be exactly 64-bit unsigned integer type.
 | 
|---|
| 27 |  * PRIu64 and PRIx64 are used for printf function to print 64-bit
 | 
|---|
| 28 |  * unsigned int and 64-bit unsigned int in hexadecimal format.
 | 
|---|
| 29 |  */
 | 
|---|
| 30 | 
 | 
|---|
| 31 | #ifndef DSFMT_H
 | 
|---|
| 32 | #define DSFMT_H
 | 
|---|
| 33 | 
 | 
|---|
| 34 | #include <stdio.h>
 | 
|---|
| 35 | #include <assert.h>
 | 
|---|
| 36 | 
 | 
|---|
| 37 | #if !defined(DSFMT_MEXP)
 | 
|---|
| 38 | #ifdef __GNUC__
 | 
|---|
| 39 |   #warning "DSFMT_MEXP is not defined. I assume DSFMT_MEXP is 19937."
 | 
|---|
| 40 | #endif
 | 
|---|
| 41 |   #define DSFMT_MEXP 19937
 | 
|---|
| 42 | #endif
 | 
|---|
| 43 | /*-----------------
 | 
|---|
| 44 |   BASIC DEFINITIONS
 | 
|---|
| 45 |   -----------------*/
 | 
|---|
| 46 | /* Mersenne Exponent. The period of the sequence 
 | 
|---|
| 47 |  *  is a multiple of 2^DSFMT_MEXP-1.
 | 
|---|
| 48 |  * #define DSFMT_MEXP 19937 */
 | 
|---|
| 49 | /** DSFMT generator has an internal state array of 128-bit integers,
 | 
|---|
| 50 |  * and N is its size. */
 | 
|---|
| 51 | #define DSFMT_N ((DSFMT_MEXP - 128) / 104 + 1)
 | 
|---|
| 52 | /** N32 is the size of internal state array when regarded as an array
 | 
|---|
| 53 |  * of 32-bit integers.*/
 | 
|---|
| 54 | #define DSFMT_N32 (DSFMT_N * 4)
 | 
|---|
| 55 | /** N64 is the size of internal state array when regarded as an array
 | 
|---|
| 56 |  * of 64-bit integers.*/
 | 
|---|
| 57 | #define DSFMT_N64 (DSFMT_N * 2)
 | 
|---|
| 58 | 
 | 
|---|
| 59 | #if !defined(DSFMT_BIG_ENDIAN)
 | 
|---|
| 60 | #  if defined(__BYTE_ORDER) && defined(__BIG_ENDIAN)
 | 
|---|
| 61 | #    if __BYTE_ORDER == __BIG_ENDIAN
 | 
|---|
| 62 | #      define DSFMT_BIG_ENDIAN 1
 | 
|---|
| 63 | #    endif
 | 
|---|
| 64 | #  elif defined(_BYTE_ORDER) && defined(_BIG_ENDIAN)
 | 
|---|
| 65 | #    if _BYTE_ORDER == _BIG_ENDIAN
 | 
|---|
| 66 | #      define DSFMT_BIG_ENDIAN 1
 | 
|---|
| 67 | #    endif
 | 
|---|
| 68 | #  elif defined(__BYTE_ORDER__) && defined(__BIG_ENDIAN__)
 | 
|---|
| 69 | #    if __BYTE_ORDER__ == __BIG_ENDIAN__
 | 
|---|
| 70 | #      define DSFMT_BIG_ENDIAN 1
 | 
|---|
| 71 | #    endif
 | 
|---|
| 72 | #  elif defined(BYTE_ORDER) && defined(BIG_ENDIAN)
 | 
|---|
| 73 | #    if BYTE_ORDER == BIG_ENDIAN
 | 
|---|
| 74 | #      define DSFMT_BIG_ENDIAN 1
 | 
|---|
| 75 | #    endif
 | 
|---|
| 76 | #  elif defined(__BIG_ENDIAN) || defined(_BIG_ENDIAN) \
 | 
|---|
| 77 |     || defined(__BIG_ENDIAN__) || defined(BIG_ENDIAN)
 | 
|---|
| 78 | #      define DSFMT_BIG_ENDIAN 1
 | 
|---|
| 79 | #  endif
 | 
|---|
| 80 | #endif
 | 
|---|
| 81 | 
 | 
|---|
| 82 | #if defined(DSFMT_BIG_ENDIAN) && defined(__amd64)
 | 
|---|
| 83 | #  undef DSFMT_BIG_ENDIAN
 | 
|---|
| 84 | #endif
 | 
|---|
| 85 | 
 | 
|---|
| 86 | #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
 | 
|---|
| 87 | #  include <inttypes.h>
 | 
|---|
| 88 | #elif defined(_MSC_VER) || defined(__BORLANDC__)
 | 
|---|
| 89 | #  if !defined(DSFMT_UINT32_DEFINED) && !defined(SFMT_UINT32_DEFINED)
 | 
|---|
| 90 | typedef unsigned int uint32_t;
 | 
|---|
| 91 | typedef unsigned __int64 uint64_t;
 | 
|---|
| 92 | #    define UINT64_C(v) (v ## ui64)
 | 
|---|
| 93 | #    define DSFMT_UINT32_DEFINED
 | 
|---|
| 94 | #    if !defined(inline)
 | 
|---|
| 95 | #      define inline __inline
 | 
|---|
| 96 | #    endif
 | 
|---|
| 97 | #  endif
 | 
|---|
| 98 | #else
 | 
|---|
| 99 | #  include <inttypes.h>
 | 
|---|
| 100 | #  if !defined(inline)
 | 
|---|
| 101 | #    if defined(__GNUC__)
 | 
|---|
| 102 | #      define inline __inline__
 | 
|---|
| 103 | #    else
 | 
|---|
| 104 | #      define inline
 | 
|---|
| 105 | #    endif
 | 
|---|
| 106 | #  endif
 | 
|---|
| 107 | #endif
 | 
|---|
| 108 | 
 | 
|---|
| 109 | #ifndef PRIu64
 | 
|---|
| 110 | #  if defined(_MSC_VER) || defined(__BORLANDC__)
 | 
|---|
| 111 | #    define PRIu64 "I64u"
 | 
|---|
| 112 | #    define PRIx64 "I64x"
 | 
|---|
| 113 | #  else
 | 
|---|
| 114 | #    define PRIu64 "llu"
 | 
|---|
| 115 | #    define PRIx64 "llx"
 | 
|---|
| 116 | #  endif
 | 
|---|
| 117 | #endif
 | 
|---|
| 118 | 
 | 
|---|
| 119 | #ifndef UINT64_C
 | 
|---|
| 120 | #  define UINT64_C(v) (v ## ULL) 
 | 
|---|
| 121 | #endif
 | 
|---|
| 122 | 
 | 
|---|
| 123 | /*------------------------------------------
 | 
|---|
| 124 |   128-bit SIMD like data type for standard C
 | 
|---|
| 125 |   ------------------------------------------*/
 | 
|---|
| 126 | #if defined(HAVE_ALTIVEC)
 | 
|---|
| 127 | #  if !defined(__APPLE__)
 | 
|---|
| 128 | #    include <altivec.h>
 | 
|---|
| 129 | #  endif
 | 
|---|
| 130 | /** 128-bit data structure */
 | 
|---|
| 131 | union W128_T {
 | 
|---|
| 132 |     vector unsigned int s;
 | 
|---|
| 133 |     uint64_t u[2];
 | 
|---|
| 134 |     uint32_t u32[4];
 | 
|---|
| 135 |     double d[2];
 | 
|---|
| 136 | };
 | 
|---|
| 137 | 
 | 
|---|
| 138 | #elif defined(HAVE_SSE2)
 | 
|---|
| 139 | #  include <emmintrin.h>
 | 
|---|
| 140 | 
 | 
|---|
| 141 | /** 128-bit data structure */
 | 
|---|
| 142 | union W128_T {
 | 
|---|
| 143 |     __m128i si;
 | 
|---|
| 144 |     __m128d sd;
 | 
|---|
| 145 |     uint64_t u[2];
 | 
|---|
| 146 |     uint32_t u32[4];
 | 
|---|
| 147 |     double d[2];
 | 
|---|
| 148 | };
 | 
|---|
| 149 | #else  /* standard C */
 | 
|---|
| 150 | /** 128-bit data structure */
 | 
|---|
| 151 | union W128_T {
 | 
|---|
| 152 |     uint64_t u[2];
 | 
|---|
| 153 |     uint32_t u32[4];
 | 
|---|
| 154 |     double d[2];
 | 
|---|
| 155 | };
 | 
|---|
| 156 | #endif
 | 
|---|
| 157 | 
 | 
|---|
| 158 | /** 128-bit data type */
 | 
|---|
| 159 | typedef union W128_T w128_t;
 | 
|---|
| 160 | 
 | 
|---|
| 161 | /** the 128-bit internal state array */
 | 
|---|
| 162 | struct DSFMT_T {
 | 
|---|
| 163 |     w128_t status[DSFMT_N + 1];
 | 
|---|
| 164 |     int idx;
 | 
|---|
| 165 | };
 | 
|---|
| 166 | typedef struct DSFMT_T dsfmt_t;
 | 
|---|
| 167 | 
 | 
|---|
| 168 | /** dsfmt internal state vector */
 | 
|---|
| 169 | extern dsfmt_t dsfmt_global_data;
 | 
|---|
| 170 | /** dsfmt mexp for check */
 | 
|---|
| 171 | extern const int dsfmt_global_mexp;
 | 
|---|
| 172 | 
 | 
|---|
| 173 | /* --- Ajout par Reza / Compilation C++ --- */ 
 | 
|---|
| 174 | #ifdef __cplusplus
 | 
|---|
| 175 | extern "C" {
 | 
|---|
| 176 | #endif
 | 
|---|
| 177 | 
 | 
|---|
| 178 | void dsfmt_gen_rand_all(dsfmt_t *dsfmt);
 | 
|---|
| 179 | void dsfmt_fill_array_open_close(dsfmt_t *dsfmt, double array[], int size);
 | 
|---|
| 180 | void dsfmt_fill_array_close_open(dsfmt_t *dsfmt, double array[], int size);
 | 
|---|
| 181 | void dsfmt_fill_array_open_open(dsfmt_t *dsfmt, double array[], int size);
 | 
|---|
| 182 | void dsfmt_fill_array_close1_open2(dsfmt_t *dsfmt, double array[], int size);
 | 
|---|
| 183 | void dsfmt_chk_init_gen_rand(dsfmt_t *dsfmt, uint32_t seed, int mexp);
 | 
|---|
| 184 | void dsfmt_chk_init_by_array(dsfmt_t *dsfmt, uint32_t init_key[],
 | 
|---|
| 185 |                              int key_length, int mexp);
 | 
|---|
| 186 | const char *dsfmt_get_idstring(void);
 | 
|---|
| 187 | int dsfmt_get_min_array_size(void);
 | 
|---|
| 188 | /* --- Ajout par Reza / Compilation C++ --- */ 
 | 
|---|
| 189 | #ifdef __cplusplus
 | 
|---|
| 190 | }
 | 
|---|
| 191 | #endif
 | 
|---|
| 192 | 
 | 
|---|
| 193 | #if defined(__GNUC__)
 | 
|---|
| 194 | #  define DSFMT_PRE_INLINE inline static
 | 
|---|
| 195 | #  define DSFMT_PST_INLINE __attribute__((always_inline))
 | 
|---|
| 196 | #elif defined(_MSC_VER) && _MSC_VER >= 1200
 | 
|---|
| 197 | #  define DSFMT_PRE_INLINE __forceinline static
 | 
|---|
| 198 | #  define DSFMT_PST_INLINE
 | 
|---|
| 199 | #else
 | 
|---|
| 200 | #  define DSFMT_PRE_INLINE inline static
 | 
|---|
| 201 | #  define DSFMT_PST_INLINE
 | 
|---|
| 202 | #endif
 | 
|---|
| 203 | DSFMT_PRE_INLINE uint32_t dsfmt_genrand_uint32(dsfmt_t *dsfmt) DSFMT_PST_INLINE;
 | 
|---|
| 204 | DSFMT_PRE_INLINE double dsfmt_genrand_close1_open2(dsfmt_t *dsfmt)
 | 
|---|
| 205 |     DSFMT_PST_INLINE;
 | 
|---|
| 206 | DSFMT_PRE_INLINE double dsfmt_genrand_close_open(dsfmt_t *dsfmt)
 | 
|---|
| 207 |     DSFMT_PST_INLINE;
 | 
|---|
| 208 | DSFMT_PRE_INLINE double dsfmt_genrand_open_close(dsfmt_t *dsfmt)
 | 
|---|
| 209 |     DSFMT_PST_INLINE;
 | 
|---|
| 210 | DSFMT_PRE_INLINE double dsfmt_genrand_open_open(dsfmt_t *dsfmt)
 | 
|---|
| 211 |     DSFMT_PST_INLINE;
 | 
|---|
| 212 | DSFMT_PRE_INLINE uint32_t dsfmt_gv_genrand_uint32(void) DSFMT_PST_INLINE;
 | 
|---|
| 213 | DSFMT_PRE_INLINE double dsfmt_gv_genrand_close1_open2(void) DSFMT_PST_INLINE;
 | 
|---|
| 214 | DSFMT_PRE_INLINE double dsfmt_gv_genrand_close_open(void) DSFMT_PST_INLINE;
 | 
|---|
| 215 | DSFMT_PRE_INLINE double dsfmt_gv_genrand_open_close(void) DSFMT_PST_INLINE;
 | 
|---|
| 216 | DSFMT_PRE_INLINE double dsfmt_gv_genrand_open_open(void) DSFMT_PST_INLINE;
 | 
|---|
| 217 | DSFMT_PRE_INLINE void dsfmt_gv_fill_array_open_close(double array[], int size)
 | 
|---|
| 218 |     DSFMT_PST_INLINE;
 | 
|---|
| 219 | DSFMT_PRE_INLINE void dsfmt_gv_fill_array_close_open(double array[], int size)
 | 
|---|
| 220 |     DSFMT_PST_INLINE;
 | 
|---|
| 221 | DSFMT_PRE_INLINE void dsfmt_gv_fill_array_open_open(double array[], int size)
 | 
|---|
| 222 |     DSFMT_PST_INLINE;
 | 
|---|
| 223 | DSFMT_PRE_INLINE void dsfmt_gv_fill_array_close1_open2(double array[], int size)
 | 
|---|
| 224 |     DSFMT_PST_INLINE;
 | 
|---|
| 225 | DSFMT_PRE_INLINE void dsfmt_gv_init_gen_rand(uint32_t seed) DSFMT_PST_INLINE;
 | 
|---|
| 226 | DSFMT_PRE_INLINE void dsfmt_gv_init_by_array(uint32_t init_key[],
 | 
|---|
| 227 |                                              int key_length) DSFMT_PST_INLINE;
 | 
|---|
| 228 | DSFMT_PRE_INLINE void dsfmt_init_gen_rand(dsfmt_t *dsfmt, uint32_t seed)
 | 
|---|
| 229 |     DSFMT_PST_INLINE;
 | 
|---|
| 230 | DSFMT_PRE_INLINE void dsfmt_init_by_array(dsfmt_t *dsfmt, uint32_t init_key[],
 | 
|---|
| 231 |                                           int key_length) DSFMT_PST_INLINE;
 | 
|---|
| 232 | 
 | 
|---|
| 233 | /**
 | 
|---|
| 234 |  * This function generates and returns unsigned 32-bit integer.
 | 
|---|
| 235 |  * This is slower than SFMT, only for convenience usage.
 | 
|---|
| 236 |  * dsfmt_init_gen_rand() or dsfmt_init_by_array() must be called
 | 
|---|
| 237 |  * before this function.
 | 
|---|
| 238 |  * @param dsfmt dsfmt internal state date
 | 
|---|
| 239 |  * @return double precision floating point pseudorandom number
 | 
|---|
| 240 |  */
 | 
|---|
| 241 | inline static uint32_t dsfmt_genrand_uint32(dsfmt_t *dsfmt) {
 | 
|---|
| 242 |     uint32_t r;
 | 
|---|
| 243 |     uint64_t *psfmt64 = &dsfmt->status[0].u[0];
 | 
|---|
| 244 | 
 | 
|---|
| 245 |     if (dsfmt->idx >= DSFMT_N64) {
 | 
|---|
| 246 |         dsfmt_gen_rand_all(dsfmt);
 | 
|---|
| 247 |         dsfmt->idx = 0;
 | 
|---|
| 248 |     }
 | 
|---|
| 249 |     r = psfmt64[dsfmt->idx++] & 0xffffffffU;
 | 
|---|
| 250 |     return r;
 | 
|---|
| 251 | }
 | 
|---|
| 252 | 
 | 
|---|
| 253 | /**
 | 
|---|
| 254 |  * This function generates and returns double precision pseudorandom
 | 
|---|
| 255 |  * number which distributes uniformly in the range [1, 2).  This is
 | 
|---|
| 256 |  * the primitive and faster than generating numbers in other ranges.
 | 
|---|
| 257 |  * dsfmt_init_gen_rand() or dsfmt_init_by_array() must be called
 | 
|---|
| 258 |  * before this function.
 | 
|---|
| 259 |  * @param dsfmt dsfmt internal state date
 | 
|---|
| 260 |  * @return double precision floating point pseudorandom number
 | 
|---|
| 261 |  */
 | 
|---|
| 262 | inline static double dsfmt_genrand_close1_open2(dsfmt_t *dsfmt) {
 | 
|---|
| 263 |     double r;
 | 
|---|
| 264 |     double *psfmt64 = &dsfmt->status[0].d[0];
 | 
|---|
| 265 | 
 | 
|---|
| 266 |     if (dsfmt->idx >= DSFMT_N64) {
 | 
|---|
| 267 |         dsfmt_gen_rand_all(dsfmt);
 | 
|---|
| 268 |         dsfmt->idx = 0;
 | 
|---|
| 269 |     }
 | 
|---|
| 270 |     r = psfmt64[dsfmt->idx++];
 | 
|---|
| 271 |     return r;
 | 
|---|
| 272 | }
 | 
|---|
| 273 | 
 | 
|---|
| 274 | /**
 | 
|---|
| 275 |  * This function generates and returns unsigned 32-bit integer.
 | 
|---|
| 276 |  * This is slower than SFMT, only for convenience usage.
 | 
|---|
| 277 |  * dsfmt_gv_init_gen_rand() or dsfmt_gv_init_by_array() must be called
 | 
|---|
| 278 |  * before this function.  This function uses \b global variables.
 | 
|---|
| 279 |  * @return double precision floating point pseudorandom number
 | 
|---|
| 280 |  */
 | 
|---|
| 281 | inline static uint32_t dsfmt_gv_genrand_uint32(void) {
 | 
|---|
| 282 |     return dsfmt_genrand_uint32(&dsfmt_global_data);
 | 
|---|
| 283 | }
 | 
|---|
| 284 | 
 | 
|---|
| 285 | /**
 | 
|---|
| 286 |  * This function generates and returns double precision pseudorandom
 | 
|---|
| 287 |  * number which distributes uniformly in the range [1, 2).
 | 
|---|
| 288 |  * dsfmt_gv_init_gen_rand() or dsfmt_gv_init_by_array() must be called
 | 
|---|
| 289 |  * before this function. This function uses \b global variables.
 | 
|---|
| 290 |  * @return double precision floating point pseudorandom number
 | 
|---|
| 291 |  */
 | 
|---|
| 292 | inline static double dsfmt_gv_genrand_close1_open2(void) {
 | 
|---|
| 293 |     return dsfmt_genrand_close1_open2(&dsfmt_global_data);
 | 
|---|
| 294 | }
 | 
|---|
| 295 | 
 | 
|---|
| 296 | /**
 | 
|---|
| 297 |  * This function generates and returns double precision pseudorandom
 | 
|---|
| 298 |  * number which distributes uniformly in the range [0, 1).
 | 
|---|
| 299 |  * dsfmt_init_gen_rand() or dsfmt_init_by_array() must be called
 | 
|---|
| 300 |  * before this function.
 | 
|---|
| 301 |  * @param dsfmt dsfmt internal state date
 | 
|---|
| 302 |  * @return double precision floating point pseudorandom number
 | 
|---|
| 303 |  */
 | 
|---|
| 304 | inline static double dsfmt_genrand_close_open(dsfmt_t *dsfmt) {
 | 
|---|
| 305 |     return dsfmt_genrand_close1_open2(dsfmt) - 1.0;
 | 
|---|
| 306 | }
 | 
|---|
| 307 | 
 | 
|---|
| 308 | /**
 | 
|---|
| 309 |  * This function generates and returns double precision pseudorandom
 | 
|---|
| 310 |  * number which distributes uniformly in the range [0, 1).
 | 
|---|
| 311 |  * dsfmt_gv_init_gen_rand() or dsfmt_gv_init_by_array() must be called
 | 
|---|
| 312 |  * before this function. This function uses \b global variables.
 | 
|---|
| 313 |  * @return double precision floating point pseudorandom number
 | 
|---|
| 314 |  */
 | 
|---|
| 315 | inline static double dsfmt_gv_genrand_close_open(void) {
 | 
|---|
| 316 |     return dsfmt_gv_genrand_close1_open2() - 1.0;
 | 
|---|
| 317 | }
 | 
|---|
| 318 | 
 | 
|---|
| 319 | /**
 | 
|---|
| 320 |  * This function generates and returns double precision pseudorandom
 | 
|---|
| 321 |  * number which distributes uniformly in the range (0, 1].
 | 
|---|
| 322 |  * dsfmt_init_gen_rand() or dsfmt_init_by_array() must be called
 | 
|---|
| 323 |  * before this function. 
 | 
|---|
| 324 |  * @param dsfmt dsfmt internal state date
 | 
|---|
| 325 |  * @return double precision floating point pseudorandom number
 | 
|---|
| 326 |  */
 | 
|---|
| 327 | inline static double dsfmt_genrand_open_close(dsfmt_t *dsfmt) {
 | 
|---|
| 328 |     return 2.0 - dsfmt_genrand_close1_open2(dsfmt);
 | 
|---|
| 329 | }
 | 
|---|
| 330 | 
 | 
|---|
| 331 | /**
 | 
|---|
| 332 |  * This function generates and returns double precision pseudorandom
 | 
|---|
| 333 |  * number which distributes uniformly in the range (0, 1].
 | 
|---|
| 334 |  * dsfmt_gv_init_gen_rand() or dsfmt_gv_init_by_array() must be called
 | 
|---|
| 335 |  * before this function. This function uses \b global variables.
 | 
|---|
| 336 |  * @return double precision floating point pseudorandom number
 | 
|---|
| 337 |  */
 | 
|---|
| 338 | inline static double dsfmt_gv_genrand_open_close(void) {
 | 
|---|
| 339 |     return 2.0 - dsfmt_gv_genrand_close1_open2();
 | 
|---|
| 340 | }
 | 
|---|
| 341 | 
 | 
|---|
| 342 | /**
 | 
|---|
| 343 |  * This function generates and returns double precision pseudorandom
 | 
|---|
| 344 |  * number which distributes uniformly in the range (0, 1).
 | 
|---|
| 345 |  * dsfmt_init_gen_rand() or dsfmt_init_by_array() must be called
 | 
|---|
| 346 |  * before this function.
 | 
|---|
| 347 |  * @param dsfmt dsfmt internal state date
 | 
|---|
| 348 |  * @return double precision floating point pseudorandom number
 | 
|---|
| 349 |  */
 | 
|---|
| 350 | inline static double dsfmt_genrand_open_open(dsfmt_t *dsfmt) {
 | 
|---|
| 351 |     double *dsfmt64 = &dsfmt->status[0].d[0];
 | 
|---|
| 352 |     union {
 | 
|---|
| 353 |         double d;
 | 
|---|
| 354 |         uint64_t u;
 | 
|---|
| 355 |     } r;
 | 
|---|
| 356 | 
 | 
|---|
| 357 |     if (dsfmt->idx >= DSFMT_N64) {
 | 
|---|
| 358 |         dsfmt_gen_rand_all(dsfmt);
 | 
|---|
| 359 |         dsfmt->idx = 0;
 | 
|---|
| 360 |     }
 | 
|---|
| 361 |     r.d = dsfmt64[dsfmt->idx++];
 | 
|---|
| 362 |     r.u |= 1;
 | 
|---|
| 363 |     return r.d - 1.0;
 | 
|---|
| 364 | }
 | 
|---|
| 365 | 
 | 
|---|
| 366 | /**
 | 
|---|
| 367 |  * This function generates and returns double precision pseudorandom
 | 
|---|
| 368 |  * number which distributes uniformly in the range (0, 1).
 | 
|---|
| 369 |  * dsfmt_gv_init_gen_rand() or dsfmt_gv_init_by_array() must be called
 | 
|---|
| 370 |  * before this function. This function uses \b global variables.
 | 
|---|
| 371 |  * @return double precision floating point pseudorandom number
 | 
|---|
| 372 |  */
 | 
|---|
| 373 | inline static double dsfmt_gv_genrand_open_open(void) {
 | 
|---|
| 374 |     return dsfmt_genrand_open_open(&dsfmt_global_data);
 | 
|---|
| 375 | }
 | 
|---|
| 376 | 
 | 
|---|
| 377 | /**
 | 
|---|
| 378 |  * This function generates double precision floating point
 | 
|---|
| 379 |  * pseudorandom numbers which distribute in the range [1, 2) to the
 | 
|---|
| 380 |  * specified array[] by one call. This function is the same as
 | 
|---|
| 381 |  * dsfmt_fill_array_close1_open2() except that this function uses
 | 
|---|
| 382 |  * \b global variables.
 | 
|---|
| 383 |  * @param array an array where pseudorandom numbers are filled
 | 
|---|
| 384 |  * by this function.
 | 
|---|
| 385 |  * @param size the number of pseudorandom numbers to be generated.
 | 
|---|
| 386 |  * see also \sa dsfmt_fill_array_close1_open2()
 | 
|---|
| 387 |  */
 | 
|---|
| 388 | inline static void dsfmt_gv_fill_array_close1_open2(double array[], int size) {
 | 
|---|
| 389 |     dsfmt_fill_array_close1_open2(&dsfmt_global_data, array, size);
 | 
|---|
| 390 | }
 | 
|---|
| 391 | 
 | 
|---|
| 392 | /**
 | 
|---|
| 393 |  * This function generates double precision floating point
 | 
|---|
| 394 |  * pseudorandom numbers which distribute in the range (0, 1] to the
 | 
|---|
| 395 |  * specified array[] by one call. This function is the same as
 | 
|---|
| 396 |  * dsfmt_gv_fill_array_close1_open2() except the distribution range.
 | 
|---|
| 397 |  * This function uses \b global variables.
 | 
|---|
| 398 |  * @param array an array where pseudorandom numbers are filled
 | 
|---|
| 399 |  * by this function.
 | 
|---|
| 400 |  * @param size the number of pseudorandom numbers to be generated.
 | 
|---|
| 401 |  * see also \sa dsfmt_fill_array_close1_open2() and \sa
 | 
|---|
| 402 |  * dsfmt_gv_fill_array_close1_open2()
 | 
|---|
| 403 |  */
 | 
|---|
| 404 | inline static void dsfmt_gv_fill_array_open_close(double array[], int size) {
 | 
|---|
| 405 |     dsfmt_fill_array_open_close(&dsfmt_global_data, array, size);
 | 
|---|
| 406 | }
 | 
|---|
| 407 | 
 | 
|---|
| 408 | /**
 | 
|---|
| 409 |  * This function generates double precision floating point
 | 
|---|
| 410 |  * pseudorandom numbers which distribute in the range [0, 1) to the
 | 
|---|
| 411 |  * specified array[] by one call. This function is the same as
 | 
|---|
| 412 |  * dsfmt_gv_fill_array_close1_open2() except the distribution range.
 | 
|---|
| 413 |  * This function uses \b global variables.
 | 
|---|
| 414 |  * @param array an array where pseudorandom numbers are filled
 | 
|---|
| 415 |  * by this function.
 | 
|---|
| 416 |  * @param size the number of pseudorandom numbers to be generated.
 | 
|---|
| 417 |  * see also \sa dsfmt_fill_array_close1_open2() \sa
 | 
|---|
| 418 |  * dsfmt_gv_fill_array_close1_open2()
 | 
|---|
| 419 |  */
 | 
|---|
| 420 | inline static void dsfmt_gv_fill_array_close_open(double array[], int size) {
 | 
|---|
| 421 |     dsfmt_fill_array_close_open(&dsfmt_global_data, array, size);
 | 
|---|
| 422 | }
 | 
|---|
| 423 | 
 | 
|---|
| 424 | /**
 | 
|---|
| 425 |  * This function generates double precision floating point
 | 
|---|
| 426 |  * pseudorandom numbers which distribute in the range (0, 1) to the
 | 
|---|
| 427 |  * specified array[] by one call. This function is the same as
 | 
|---|
| 428 |  * dsfmt_gv_fill_array_close1_open2() except the distribution range.
 | 
|---|
| 429 |  * This function uses \b global variables.
 | 
|---|
| 430 |  * @param array an array where pseudorandom numbers are filled
 | 
|---|
| 431 |  * by this function.
 | 
|---|
| 432 |  * @param size the number of pseudorandom numbers to be generated.
 | 
|---|
| 433 |  * see also \sa dsfmt_fill_array_close1_open2() \sa
 | 
|---|
| 434 |  * dsfmt_gv_fill_array_close1_open2()
 | 
|---|
| 435 |  */
 | 
|---|
| 436 | inline static void dsfmt_gv_fill_array_open_open(double array[], int size) {
 | 
|---|
| 437 |     dsfmt_fill_array_open_open(&dsfmt_global_data, array, size);
 | 
|---|
| 438 | }
 | 
|---|
| 439 | 
 | 
|---|
| 440 | /**
 | 
|---|
| 441 |  * This function initializes the internal state array with a 32-bit
 | 
|---|
| 442 |  * integer seed.
 | 
|---|
| 443 |  * @param dsfmt dsfmt state vector.
 | 
|---|
| 444 |  * @param seed a 32-bit integer used as the seed.
 | 
|---|
| 445 |  */
 | 
|---|
| 446 | inline static void dsfmt_init_gen_rand(dsfmt_t *dsfmt, uint32_t seed) {
 | 
|---|
| 447 |     dsfmt_chk_init_gen_rand(dsfmt, seed, DSFMT_MEXP);
 | 
|---|
| 448 | }
 | 
|---|
| 449 | 
 | 
|---|
| 450 | /**
 | 
|---|
| 451 |  * This function initializes the internal state array with a 32-bit
 | 
|---|
| 452 |  * integer seed. This function uses \b global variables.
 | 
|---|
| 453 |  * @param seed a 32-bit integer used as the seed.
 | 
|---|
| 454 |  * see also \sa dsfmt_init_gen_rand()
 | 
|---|
| 455 |  */
 | 
|---|
| 456 | inline static void dsfmt_gv_init_gen_rand(uint32_t seed) {
 | 
|---|
| 457 |     dsfmt_init_gen_rand(&dsfmt_global_data, seed);
 | 
|---|
| 458 | }
 | 
|---|
| 459 | 
 | 
|---|
| 460 | /**
 | 
|---|
| 461 |  * This function initializes the internal state array,
 | 
|---|
| 462 |  * with an array of 32-bit integers used as the seeds.
 | 
|---|
| 463 |  * @param dsfmt dsfmt state vector
 | 
|---|
| 464 |  * @param init_key the array of 32-bit integers, used as a seed.
 | 
|---|
| 465 |  * @param key_length the length of init_key.
 | 
|---|
| 466 |  */
 | 
|---|
| 467 | inline static void dsfmt_init_by_array(dsfmt_t *dsfmt, uint32_t init_key[],
 | 
|---|
| 468 |                                        int key_length) {
 | 
|---|
| 469 |     dsfmt_chk_init_by_array(dsfmt, init_key, key_length, DSFMT_MEXP);
 | 
|---|
| 470 | }
 | 
|---|
| 471 | 
 | 
|---|
| 472 | /**
 | 
|---|
| 473 |  * This function initializes the internal state array,
 | 
|---|
| 474 |  * with an array of 32-bit integers used as the seeds.
 | 
|---|
| 475 |  * This function uses \b global variables.
 | 
|---|
| 476 |  * @param init_key the array of 32-bit integers, used as a seed.
 | 
|---|
| 477 |  * @param key_length the length of init_key.
 | 
|---|
| 478 |  * see also \sa dsfmt_init_by_array()
 | 
|---|
| 479 |  */
 | 
|---|
| 480 | inline static void dsfmt_gv_init_by_array(uint32_t init_key[], int key_length) {
 | 
|---|
| 481 |     dsfmt_init_by_array(&dsfmt_global_data, init_key, key_length);
 | 
|---|
| 482 | }
 | 
|---|
| 483 | 
 | 
|---|
| 484 | #if !defined(DSFMT_DO_NOT_USE_OLD_NAMES)
 | 
|---|
| 485 | DSFMT_PRE_INLINE const char *get_idstring(void) DSFMT_PST_INLINE;
 | 
|---|
| 486 | DSFMT_PRE_INLINE int get_min_array_size(void) DSFMT_PST_INLINE;
 | 
|---|
| 487 | DSFMT_PRE_INLINE void init_gen_rand(uint32_t seed) DSFMT_PST_INLINE;
 | 
|---|
| 488 | DSFMT_PRE_INLINE void init_by_array(uint32_t init_key[], int key_length)
 | 
|---|
| 489 |     DSFMT_PST_INLINE;
 | 
|---|
| 490 | DSFMT_PRE_INLINE double genrand_close1_open2(void) DSFMT_PST_INLINE;
 | 
|---|
| 491 | DSFMT_PRE_INLINE double genrand_close_open(void) DSFMT_PST_INLINE;
 | 
|---|
| 492 | DSFMT_PRE_INLINE double genrand_open_close(void) DSFMT_PST_INLINE;
 | 
|---|
| 493 | DSFMT_PRE_INLINE double genrand_open_open(void) DSFMT_PST_INLINE;
 | 
|---|
| 494 | DSFMT_PRE_INLINE void fill_array_open_close(double array[], int size)
 | 
|---|
| 495 |     DSFMT_PST_INLINE;
 | 
|---|
| 496 | DSFMT_PRE_INLINE void fill_array_close_open(double array[], int size)
 | 
|---|
| 497 |     DSFMT_PST_INLINE;
 | 
|---|
| 498 | DSFMT_PRE_INLINE void fill_array_open_open(double array[], int size)
 | 
|---|
| 499 |     DSFMT_PST_INLINE;
 | 
|---|
| 500 | DSFMT_PRE_INLINE void fill_array_close1_open2(double array[], int size)
 | 
|---|
| 501 |     DSFMT_PST_INLINE;
 | 
|---|
| 502 | 
 | 
|---|
| 503 | /**
 | 
|---|
| 504 |  * This function is just the same as dsfmt_get_idstring().
 | 
|---|
| 505 |  * @return id string.
 | 
|---|
| 506 |  * see also \sa dsfmt_get_idstring()
 | 
|---|
| 507 |  */
 | 
|---|
| 508 | inline static const char *get_idstring(void) {
 | 
|---|
| 509 |     return dsfmt_get_idstring();
 | 
|---|
| 510 | }
 | 
|---|
| 511 | 
 | 
|---|
| 512 | /**
 | 
|---|
| 513 |  * This function is just the same as dsfmt_get_min_array_size().
 | 
|---|
| 514 |  * @return minimum size of array used for fill_array functions.
 | 
|---|
| 515 |  * see also \sa dsfmt_get_min_array_size()
 | 
|---|
| 516 |  */
 | 
|---|
| 517 | inline static int get_min_array_size(void) {
 | 
|---|
| 518 |     return dsfmt_get_min_array_size();
 | 
|---|
| 519 | }
 | 
|---|
| 520 | 
 | 
|---|
| 521 | /**
 | 
|---|
| 522 |  * This function is just the same as dsfmt_gv_init_gen_rand().
 | 
|---|
| 523 |  * @param seed a 32-bit integer used as the seed.
 | 
|---|
| 524 |  * see also \sa dsfmt_gv_init_gen_rand(), \sa dsfmt_init_gen_rand().
 | 
|---|
| 525 |  */
 | 
|---|
| 526 | inline static void init_gen_rand(uint32_t seed) {
 | 
|---|
| 527 |     dsfmt_gv_init_gen_rand(seed);
 | 
|---|
| 528 | }
 | 
|---|
| 529 | 
 | 
|---|
| 530 | /**
 | 
|---|
| 531 |  * This function is just the same as dsfmt_gv_init_by_array().
 | 
|---|
| 532 |  * @param init_key the array of 32-bit integers, used as a seed.
 | 
|---|
| 533 |  * @param key_length the length of init_key.
 | 
|---|
| 534 |  * see also \sa dsfmt_gv_init_by_array(), \sa dsfmt_init_by_array().
 | 
|---|
| 535 |  */
 | 
|---|
| 536 | inline static void init_by_array(uint32_t init_key[], int key_length) {
 | 
|---|
| 537 |     dsfmt_gv_init_by_array(init_key, key_length);
 | 
|---|
| 538 | }
 | 
|---|
| 539 | 
 | 
|---|
| 540 | /**
 | 
|---|
| 541 |  * This function is just the same as dsfmt_gv_genrand_close1_open2().
 | 
|---|
| 542 |  * @return double precision floating point number.
 | 
|---|
| 543 |  * see also \sa dsfmt_genrand_close1_open2() \sa
 | 
|---|
| 544 |  * dsfmt_gv_genrand_close1_open2()
 | 
|---|
| 545 |  */
 | 
|---|
| 546 | inline static double genrand_close1_open2(void) {
 | 
|---|
| 547 |     return dsfmt_gv_genrand_close1_open2();
 | 
|---|
| 548 | }
 | 
|---|
| 549 | 
 | 
|---|
| 550 | /**
 | 
|---|
| 551 |  * This function is just the same as dsfmt_gv_genrand_close_open().
 | 
|---|
| 552 |  * @return double precision floating point number.
 | 
|---|
| 553 |  * see also \sa dsfmt_genrand_close_open() \sa
 | 
|---|
| 554 |  * dsfmt_gv_genrand_close_open()
 | 
|---|
| 555 |  */
 | 
|---|
| 556 | inline static double genrand_close_open(void) {
 | 
|---|
| 557 |     return dsfmt_gv_genrand_close_open();
 | 
|---|
| 558 | }
 | 
|---|
| 559 | 
 | 
|---|
| 560 | /**
 | 
|---|
| 561 |  * This function is just the same as dsfmt_gv_genrand_open_close().
 | 
|---|
| 562 |  * @return double precision floating point number.
 | 
|---|
| 563 |  * see also \sa dsfmt_genrand_open_close() \sa
 | 
|---|
| 564 |  * dsfmt_gv_genrand_open_close()
 | 
|---|
| 565 |  */
 | 
|---|
| 566 | inline static double genrand_open_close(void) {
 | 
|---|
| 567 |     return dsfmt_gv_genrand_open_close();
 | 
|---|
| 568 | }
 | 
|---|
| 569 | 
 | 
|---|
| 570 | /**
 | 
|---|
| 571 |  * This function is just the same as dsfmt_gv_genrand_open_open().
 | 
|---|
| 572 |  * @return double precision floating point number.
 | 
|---|
| 573 |  * see also \sa dsfmt_genrand_open_open() \sa
 | 
|---|
| 574 |  * dsfmt_gv_genrand_open_open()
 | 
|---|
| 575 |  */
 | 
|---|
| 576 | inline static double genrand_open_open(void) {
 | 
|---|
| 577 |     return dsfmt_gv_genrand_open_open();
 | 
|---|
| 578 | }
 | 
|---|
| 579 | 
 | 
|---|
| 580 | /**
 | 
|---|
| 581 |  * This function is juset the same as dsfmt_gv_fill_array_open_close().
 | 
|---|
| 582 |  * @param array an array where pseudorandom numbers are filled
 | 
|---|
| 583 |  * by this function.
 | 
|---|
| 584 |  * @param size the number of pseudorandom numbers to be generated.
 | 
|---|
| 585 |  * see also \sa dsfmt_gv_fill_array_open_close(), \sa
 | 
|---|
| 586 |  * dsfmt_fill_array_close1_open2(), \sa
 | 
|---|
| 587 |  * dsfmt_gv_fill_array_close1_open2()
 | 
|---|
| 588 |  */
 | 
|---|
| 589 | inline static void fill_array_open_close(double array[], int size) {
 | 
|---|
| 590 |     dsfmt_gv_fill_array_open_close(array, size);
 | 
|---|
| 591 | }
 | 
|---|
| 592 | 
 | 
|---|
| 593 | /**
 | 
|---|
| 594 |  * This function is juset the same as dsfmt_gv_fill_array_close_open().
 | 
|---|
| 595 |  * @param array an array where pseudorandom numbers are filled
 | 
|---|
| 596 |  * by this function.
 | 
|---|
| 597 |  * @param size the number of pseudorandom numbers to be generated.
 | 
|---|
| 598 |  * see also \sa dsfmt_gv_fill_array_close_open(), \sa
 | 
|---|
| 599 |  * dsfmt_fill_array_close1_open2(), \sa
 | 
|---|
| 600 |  * dsfmt_gv_fill_array_close1_open2()
 | 
|---|
| 601 |  */
 | 
|---|
| 602 | inline static void fill_array_close_open(double array[], int size) {
 | 
|---|
| 603 |     dsfmt_gv_fill_array_close_open(array, size);
 | 
|---|
| 604 | }
 | 
|---|
| 605 | 
 | 
|---|
| 606 | /**
 | 
|---|
| 607 |  * This function is juset the same as dsfmt_gv_fill_array_open_open().
 | 
|---|
| 608 |  * @param array an array where pseudorandom numbers are filled
 | 
|---|
| 609 |  * by this function.
 | 
|---|
| 610 |  * @param size the number of pseudorandom numbers to be generated.
 | 
|---|
| 611 |  * see also \sa dsfmt_gv_fill_array_open_open(), \sa
 | 
|---|
| 612 |  * dsfmt_fill_array_close1_open2(), \sa
 | 
|---|
| 613 |  * dsfmt_gv_fill_array_close1_open2()
 | 
|---|
| 614 |  */
 | 
|---|
| 615 | inline static void fill_array_open_open(double array[], int size) {
 | 
|---|
| 616 |     dsfmt_gv_fill_array_open_open(array, size);
 | 
|---|
| 617 | }
 | 
|---|
| 618 | 
 | 
|---|
| 619 | /**
 | 
|---|
| 620 |  * This function is juset the same as dsfmt_gv_fill_array_close1_open2().
 | 
|---|
| 621 |  * @param array an array where pseudorandom numbers are filled
 | 
|---|
| 622 |  * by this function.
 | 
|---|
| 623 |  * @param size the number of pseudorandom numbers to be generated.
 | 
|---|
| 624 |  * see also \sa dsfmt_fill_array_close1_open2(), \sa
 | 
|---|
| 625 |  * dsfmt_gv_fill_array_close1_open2()
 | 
|---|
| 626 |  */
 | 
|---|
| 627 | inline static void fill_array_close1_open2(double array[], int size) {
 | 
|---|
| 628 |     dsfmt_gv_fill_array_close1_open2(array, size);
 | 
|---|
| 629 | }
 | 
|---|
| 630 | #endif /* DSFMT_DO_NOT_USE_OLD_NAMES */
 | 
|---|
| 631 | 
 | 
|---|
| 632 | #endif /* DSFMT_H */
 | 
|---|