INGOR
Loading...
Searching...
No Matches
ytRNG_dSFMT.h
1/*
2 ytRNG_dSMFT.{h,c} : Random number generator
3
4 This is the wrapper source code of the dSFMT for ytLib.
5
6 dSFMT ORIGINAL LICENSE
7
8 Copyright (c) 2006,2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
9 University.
10 Copyright (c) 2012 Mutsuo Saito, Makoto Matsumoto, Hiroshima University
11 and The University of Tokyo.
12 All rights reserved.
13
14 Redistribution and use in source and binary forms, with or without
15 modification, are permitted provided that the following conditions are
16 met:
17
18 * Redistributions of source code must retain the above copyright
19 notice, this list of conditions and the following disclaimer.
20 * Redistributions in binary form must reproduce the above
21 copyright notice, this list of conditions and the following
22 disclaimer in the documentation and/or other materials provided
23 with the distribution.
24 * Neither the names of Hiroshima University, The University of
25 Tokyo nor the names of its contributors may be used to endorse
26 or promote products derived from this software without specific
27 prior written permission.
28
29 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40*/
41
42#ifndef __YTLIB_RNG_DSFMT_H
43#define __YTLIB_RNG_DSFMT_H
44
45#include <stdio.h>
46#include <stdlib.h>
47
48#define DSFMT_MEXP 19937
49
50#if defined __GNUC__ && !defined __GNUC_STDC_INLINE__ && !defined __GNUC_GNU_INLINE__
51# define __GNUC_GNU_INLINE__ 1
52#endif
53
54#ifndef INLINE
55# if __GNUC__ && !__GNUC_STDC_INLINE__
56# define INLINE extern inline
57# else
58# define INLINE inline
59# endif
60#endif
61
62/*
63 * @file dSFMT.h
64 *
65 * @brief double precision SIMD oriented Fast Mersenne Twister(dSFMT)
66 * pseudorandom number generator based on IEEE 754 format.
67 *
68 * @author Mutsuo Saito (Hiroshima University)
69 * @author Makoto Matsumoto (Hiroshima University)
70 *
71 * Copyright (C) 2007, 2008 Mutsuo Saito, Makoto Matsumoto and
72 * Hiroshima University. All rights reserved.
73 *
74 * The new BSD License is applied to this software.
75 * see LICENSE.txt
76 *
77 * @note We assume that your system has inttypes.h. If your system
78 * doesn't have inttypes.h, you have to typedef uint32_t and uint64_t,
79 * and you have to define PRIu64 and PRIx64 in this file as follows:
80 * @verbatim
81 typedef unsigned int uint32_t
82 typedef unsigned long long uint64_t
83 #define PRIu64 "llu"
84 #define PRIx64 "llx"
85@endverbatim
86 * uint32_t must be exactly 32-bit unsigned integer type (no more, no
87 * less), and uint64_t must be exactly 64-bit unsigned integer type.
88 * PRIu64 and PRIx64 are used for printf function to print 64-bit
89 * unsigned int and 64-bit unsigned int in hexadecimal format.
90 */
91
92#include <stdio.h>
93#include <assert.h>
94
95#if !defined(DSFMT_MEXP)
96#ifdef __GNUC__
97 #warning "DSFMT_MEXP is not defined. I assume DSFMT_MEXP is 19937."
98#endif
99 #define DSFMT_MEXP 19937
100#endif
101/*-----------------
102 BASIC DEFINITIONS
103 -----------------*/
104/* Mersenne Exponent. The period of the sequence
105 * is a multiple of 2^DSFMT_MEXP-1.
106 * #define DSFMT_MEXP 19937 */
107/* DSFMT generator has an internal state array of 128-bit integers,
108 * and N is its size. */
109#define DSFMT_N ((DSFMT_MEXP - 128) / 104 + 1)
110/* N32 is the size of internal state array when regarded as an array
111 * of 32-bit integers.*/
112#define DSFMT_N32 (DSFMT_N * 4)
113/* N64 is the size of internal state array when regarded as an array
114 * of 64-bit integers.*/
115#define DSFMT_N64 (DSFMT_N * 2)
116
117#if !defined(DSFMT_BIG_ENDIAN)
118# if defined(__BYTE_ORDER) && defined(__BIG_ENDIAN)
119# if __BYTE_ORDER == __BIG_ENDIAN
120# define DSFMT_BIG_ENDIAN 1
121# endif
122# elif defined(_BYTE_ORDER) && defined(_BIG_ENDIAN)
123# if _BYTE_ORDER == _BIG_ENDIAN
124# define DSFMT_BIG_ENDIAN 1
125# endif
126# elif defined(__BYTE_ORDER__) && defined(__BIG_ENDIAN__)
127# if __BYTE_ORDER__ == __BIG_ENDIAN__
128# define DSFMT_BIG_ENDIAN 1
129# endif
130# elif defined(BYTE_ORDER) && defined(BIG_ENDIAN)
131# if BYTE_ORDER == BIG_ENDIAN
132# define DSFMT_BIG_ENDIAN 1
133# endif
134# elif defined(__BIG_ENDIAN) || defined(_BIG_ENDIAN) \
135 || defined(__BIG_ENDIAN__) || defined(BIG_ENDIAN)
136# define DSFMT_BIG_ENDIAN 1
137# endif
138#endif
139
140#if defined(DSFMT_BIG_ENDIAN) && defined(__amd64)
141# undef DSFMT_BIG_ENDIAN
142#endif
143
144#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
145# include <inttypes.h>
146#elif defined(_MSC_VER) || defined(__BORLANDC__)
147# if !defined(DSFMT_UINT32_DEFINED) && !defined(SFMT_UINT32_DEFINED)
148typedef unsigned int uint32_t;
149typedef unsigned __int64 uint64_t;
150# define UINT64_C(v) (v ## ui64)
151# define DSFMT_UINT32_DEFINED
152# if !defined(inline)
153# define inline __inline
154# endif
155# endif
156#else
157# include <inttypes.h>
158# if !defined(inline)
159# if defined(__GNUC__)
160# define inline __inline__
161# else
162# define inline
163# endif
164# endif
165#endif
166
167#ifndef PRIu64
168# if defined(_MSC_VER) || defined(__BORLANDC__)
169# define PRIu64 "I64u"
170# define PRIx64 "I64x"
171# else
172# define PRIu64 "llu"
173# define PRIx64 "llx"
174# endif
175#endif
176
177#ifndef UINT64_C
178# define UINT64_C(v) (v ## ULL)
179#endif
180
181/*------------------------------------------
182 128-bit SIMD like data type for standard C
183 ------------------------------------------*/
184#if defined(HAVE_ALTIVEC)
185# if !defined(__APPLE__)
186# include <altivec.h>
187# endif
188/* 128-bit data structure */
189union W128_T {
190 vector unsigned int s;
191 uint64_t u[2];
192 uint32_t u32[4];
193 double d[2];
194};
195
196#elif defined(HAVE_SSE2)
197# include <emmintrin.h>
198
199/* 128-bit data structure */
200union W128_T {
201 __m128i si;
202 __m128d sd;
203 uint64_t u[2];
204 uint32_t u32[4];
205 double d[2];
206};
207#else /* standard C */
208/* 128-bit data structure */
209union W128_T {
210 uint64_t u[2];
211 uint32_t u32[4];
212 double d[2];
213};
214#endif
215
217typedef union W128_T w128_t;
218
219/* the 128-bit internal state array */
220struct DSFMT_T {
221 w128_t status[DSFMT_N + 1];
222 int idx;
223};
224typedef struct DSFMT_T dsfmt_t;
225
226/* dsfmt internal state vector */
227extern dsfmt_t dsfmt_global_data;
228/* dsfmt mexp for check */
229extern const int dsfmt_global_mexp;
230
231void dsfmt_gen_rand_all(dsfmt_t *dsfmt);
232void dsfmt_fill_array_open_close(dsfmt_t *dsfmt, double array[], int size);
233void dsfmt_fill_array_close_open(dsfmt_t *dsfmt, double array[], int size);
234void dsfmt_fill_array_open_open(dsfmt_t *dsfmt, double array[], int size);
235void dsfmt_fill_array_close1_open2(dsfmt_t *dsfmt, double array[], int size);
236void dsfmt_chk_init_gen_rand(dsfmt_t *dsfmt, uint32_t seed, int mexp);
237void dsfmt_chk_init_by_array(dsfmt_t *dsfmt, uint32_t init_key[],
238 int key_length, int mexp);
239const char *dsfmt_get_idstring(void);
240int dsfmt_get_min_array_size(void);
241
242#if defined(__GNUC__)
243# define DSFMT_PRE_INLINE inline static
244# define DSFMT_PST_INLINE __attribute__((always_inline))
245#elif defined(_MSC_VER) && _MSC_VER >= 1200
246# define DSFMT_PRE_INLINE __forceinline static
247# define DSFMT_PST_INLINE
248#else
249# define DSFMT_PRE_INLINE inline static
250# define DSFMT_PST_INLINE
251#endif
252DSFMT_PRE_INLINE uint32_t dsfmt_genrand_uint32(dsfmt_t *dsfmt) DSFMT_PST_INLINE;
253DSFMT_PRE_INLINE double dsfmt_genrand_close1_open2(dsfmt_t *dsfmt)
254 DSFMT_PST_INLINE;
255DSFMT_PRE_INLINE double dsfmt_genrand_close_open(dsfmt_t *dsfmt)
256 DSFMT_PST_INLINE;
257DSFMT_PRE_INLINE double dsfmt_genrand_open_close(dsfmt_t *dsfmt)
258 DSFMT_PST_INLINE;
259DSFMT_PRE_INLINE double dsfmt_genrand_open_open(dsfmt_t *dsfmt)
260 DSFMT_PST_INLINE;
261DSFMT_PRE_INLINE uint32_t dsfmt_gv_genrand_uint32(void) DSFMT_PST_INLINE;
262DSFMT_PRE_INLINE double dsfmt_gv_genrand_close1_open2(void) DSFMT_PST_INLINE;
263DSFMT_PRE_INLINE double dsfmt_gv_genrand_close_open(void) DSFMT_PST_INLINE;
264DSFMT_PRE_INLINE double dsfmt_gv_genrand_open_close(void) DSFMT_PST_INLINE;
265DSFMT_PRE_INLINE double dsfmt_gv_genrand_open_open(void) DSFMT_PST_INLINE;
266DSFMT_PRE_INLINE void dsfmt_gv_fill_array_open_close(double array[], int size)
267 DSFMT_PST_INLINE;
268DSFMT_PRE_INLINE void dsfmt_gv_fill_array_close_open(double array[], int size)
269 DSFMT_PST_INLINE;
270DSFMT_PRE_INLINE void dsfmt_gv_fill_array_open_open(double array[], int size)
271 DSFMT_PST_INLINE;
272DSFMT_PRE_INLINE void dsfmt_gv_fill_array_close1_open2(double array[], int size)
273 DSFMT_PST_INLINE;
274DSFMT_PRE_INLINE void dsfmt_gv_init_gen_rand(uint32_t seed) DSFMT_PST_INLINE;
275DSFMT_PRE_INLINE void dsfmt_gv_init_by_array(uint32_t init_key[],
276 int key_length) DSFMT_PST_INLINE;
277DSFMT_PRE_INLINE void dsfmt_init_gen_rand(dsfmt_t *dsfmt, uint32_t seed)
278 DSFMT_PST_INLINE;
279DSFMT_PRE_INLINE void dsfmt_init_by_array(dsfmt_t *dsfmt, uint32_t init_key[],
280 int key_length) DSFMT_PST_INLINE;
281
282/*
283 * This function generates and returns unsigned 32-bit integer.
284 * This is slower than SFMT, only for convenience usage.
285 * dsfmt_init_gen_rand() or dsfmt_init_by_array() must be called
286 * before this function.
287 * @param dsfmt dsfmt internal state date
288 * @return double precision floating point pseudorandom number
289 */
290inline static uint32_t dsfmt_genrand_uint32(dsfmt_t *dsfmt) {
291 uint32_t r;
292 uint64_t *psfmt64 = &dsfmt->status[0].u[0];
293
294 if (dsfmt->idx >= DSFMT_N64) {
295 dsfmt_gen_rand_all(dsfmt);
296 dsfmt->idx = 0;
297 }
298 r = psfmt64[dsfmt->idx++] & 0xffffffffU;
299 return r;
300}
301
302/*
303 * This function generates and returns double precision pseudorandom
304 * number which distributes uniformly in the range [1, 2). This is
305 * the primitive and faster than generating numbers in other ranges.
306 * dsfmt_init_gen_rand() or dsfmt_init_by_array() must be called
307 * before this function.
308 * @param dsfmt dsfmt internal state date
309 * @return double precision floating point pseudorandom number
310 */
311inline static double dsfmt_genrand_close1_open2(dsfmt_t *dsfmt) {
312 double r;
313 double *psfmt64 = &dsfmt->status[0].d[0];
314
315 if (dsfmt->idx >= DSFMT_N64) {
316 dsfmt_gen_rand_all(dsfmt);
317 dsfmt->idx = 0;
318 }
319 r = psfmt64[dsfmt->idx++];
320 return r;
321}
322
323/*
324 * This function generates and returns unsigned 32-bit integer.
325 * This is slower than SFMT, only for convenience usage.
326 * dsfmt_gv_init_gen_rand() or dsfmt_gv_init_by_array() must be called
327 * before this function. This function uses \b global variables.
328 * @return double precision floating point pseudorandom number
329 */
330inline static uint32_t dsfmt_gv_genrand_uint32(void) {
331 return dsfmt_genrand_uint32(&dsfmt_global_data);
332}
333
334/*
335 * This function generates and returns double precision pseudorandom
336 * number which distributes uniformly in the range [1, 2).
337 * dsfmt_gv_init_gen_rand() or dsfmt_gv_init_by_array() must be called
338 * before this function. This function uses \b global variables.
339 * @return double precision floating point pseudorandom number
340 */
341inline static double dsfmt_gv_genrand_close1_open2(void) {
342 return dsfmt_genrand_close1_open2(&dsfmt_global_data);
343}
344
345/*
346 * This function generates and returns double precision pseudorandom
347 * number which distributes uniformly in the range [0, 1).
348 * dsfmt_init_gen_rand() or dsfmt_init_by_array() must be called
349 * before this function.
350 * @param dsfmt dsfmt internal state date
351 * @return double precision floating point pseudorandom number
352 */
353inline static double dsfmt_genrand_close_open(dsfmt_t *dsfmt) {
354 return dsfmt_genrand_close1_open2(dsfmt) - 1.0;
355}
356
357/*
358 * This function generates and returns double precision pseudorandom
359 * number which distributes uniformly in the range [0, 1).
360 * dsfmt_gv_init_gen_rand() or dsfmt_gv_init_by_array() must be called
361 * before this function. This function uses \b global variables.
362 * @return double precision floating point pseudorandom number
363 */
364inline static double dsfmt_gv_genrand_close_open(void) {
365 return dsfmt_gv_genrand_close1_open2() - 1.0;
366}
367
368/*
369 * This function generates and returns double precision pseudorandom
370 * number which distributes uniformly in the range (0, 1].
371 * dsfmt_init_gen_rand() or dsfmt_init_by_array() must be called
372 * before this function.
373 * @param dsfmt dsfmt internal state date
374 * @return double precision floating point pseudorandom number
375 */
376inline static double dsfmt_genrand_open_close(dsfmt_t *dsfmt) {
377 return 2.0 - dsfmt_genrand_close1_open2(dsfmt);
378}
379
380/*
381 * This function generates and returns double precision pseudorandom
382 * number which distributes uniformly in the range (0, 1].
383 * dsfmt_gv_init_gen_rand() or dsfmt_gv_init_by_array() must be called
384 * before this function. This function uses \b global variables.
385 * @return double precision floating point pseudorandom number
386 */
387inline static double dsfmt_gv_genrand_open_close(void) {
388 return 2.0 - dsfmt_gv_genrand_close1_open2();
389}
390
391/*
392 * This function generates and returns double precision pseudorandom
393 * number which distributes uniformly in the range (0, 1).
394 * dsfmt_init_gen_rand() or dsfmt_init_by_array() must be called
395 * before this function.
396 * @param dsfmt dsfmt internal state date
397 * @return double precision floating point pseudorandom number
398 */
399inline static double dsfmt_genrand_open_open(dsfmt_t *dsfmt) {
400 double *dsfmt64 = &dsfmt->status[0].d[0];
401 union {
402 double d;
403 uint64_t u;
404 } r;
405
406 if (dsfmt->idx >= DSFMT_N64) {
407 dsfmt_gen_rand_all(dsfmt);
408 dsfmt->idx = 0;
409 }
410 r.d = dsfmt64[dsfmt->idx++];
411 r.u |= 1;
412 return r.d - 1.0;
413}
414
415/*
416 * This function generates and returns double precision pseudorandom
417 * number which distributes uniformly in the range (0, 1).
418 * dsfmt_gv_init_gen_rand() or dsfmt_gv_init_by_array() must be called
419 * before this function. This function uses \b global variables.
420 * @return double precision floating point pseudorandom number
421 */
422inline static double dsfmt_gv_genrand_open_open(void) {
423 return dsfmt_genrand_open_open(&dsfmt_global_data);
424}
425
426/*
427 * This function generates double precision floating point
428 * pseudorandom numbers which distribute in the range [1, 2) to the
429 * specified array[] by one call. This function is the same as
430 * dsfmt_fill_array_close1_open2() except that this function uses
431 * \b global variables.
432 * @param array an array where pseudorandom numbers are filled
433 * by this function.
434 * @param size the number of pseudorandom numbers to be generated.
435 * see also \sa dsfmt_fill_array_close1_open2()
436 */
437inline static void dsfmt_gv_fill_array_close1_open2(double array[], int size) {
438 dsfmt_fill_array_close1_open2(&dsfmt_global_data, array, size);
439}
440
441/*
442 * This function generates double precision floating point
443 * pseudorandom numbers which distribute in the range (0, 1] to the
444 * specified array[] by one call. This function is the same as
445 * dsfmt_gv_fill_array_close1_open2() except the distribution range.
446 * This function uses \b global variables.
447 * @param array an array where pseudorandom numbers are filled
448 * by this function.
449 * @param size the number of pseudorandom numbers to be generated.
450 * see also \sa dsfmt_fill_array_close1_open2() and \sa
451 * dsfmt_gv_fill_array_close1_open2()
452 */
453inline static void dsfmt_gv_fill_array_open_close(double array[], int size) {
454 dsfmt_fill_array_open_close(&dsfmt_global_data, array, size);
455}
456
457/*
458 * This function generates double precision floating point
459 * pseudorandom numbers which distribute in the range [0, 1) to the
460 * specified array[] by one call. This function is the same as
461 * dsfmt_gv_fill_array_close1_open2() except the distribution range.
462 * This function uses \b global variables.
463 * @param array an array where pseudorandom numbers are filled
464 * by this function.
465 * @param size the number of pseudorandom numbers to be generated.
466 * see also \sa dsfmt_fill_array_close1_open2() \sa
467 * dsfmt_gv_fill_array_close1_open2()
468 */
469inline static void dsfmt_gv_fill_array_close_open(double array[], int size) {
470 dsfmt_fill_array_close_open(&dsfmt_global_data, array, size);
471}
472
473/*
474 * This function generates double precision floating point
475 * pseudorandom numbers which distribute in the range (0, 1) to the
476 * specified array[] by one call. This function is the same as
477 * dsfmt_gv_fill_array_close1_open2() except the distribution range.
478 * This function uses \b global variables.
479 * @param array an array where pseudorandom numbers are filled
480 * by this function.
481 * @param size the number of pseudorandom numbers to be generated.
482 * see also \sa dsfmt_fill_array_close1_open2() \sa
483 * dsfmt_gv_fill_array_close1_open2()
484 */
485inline static void dsfmt_gv_fill_array_open_open(double array[], int size) {
486 dsfmt_fill_array_open_open(&dsfmt_global_data, array, size);
487}
488
489/*
490 * This function initializes the internal state array with a 32-bit
491 * integer seed.
492 * @param dsfmt dsfmt state vector.
493 * @param seed a 32-bit integer used as the seed.
494 */
495inline static void dsfmt_init_gen_rand(dsfmt_t *dsfmt, uint32_t seed) {
496 dsfmt_chk_init_gen_rand(dsfmt, seed, DSFMT_MEXP);
497}
498
499/*
500 * This function initializes the internal state array with a 32-bit
501 * integer seed. This function uses \b global variables.
502 * @param seed a 32-bit integer used as the seed.
503 * see also \sa dsfmt_init_gen_rand()
504 */
505inline static void dsfmt_gv_init_gen_rand(uint32_t seed) {
506 dsfmt_init_gen_rand(&dsfmt_global_data, seed);
507}
508
509/*
510 * This function initializes the internal state array,
511 * with an array of 32-bit integers used as the seeds.
512 * @param dsfmt dsfmt state vector
513 * @param init_key the array of 32-bit integers, used as a seed.
514 * @param key_length the length of init_key.
515 */
516inline static void dsfmt_init_by_array(dsfmt_t *dsfmt, uint32_t init_key[],
517 int key_length) {
518 dsfmt_chk_init_by_array(dsfmt, init_key, key_length, DSFMT_MEXP);
519}
520
521/*
522 * This function initializes the internal state array,
523 * with an array of 32-bit integers used as the seeds.
524 * This function uses \b global variables.
525 * @param init_key the array of 32-bit integers, used as a seed.
526 * @param key_length the length of init_key.
527 * see also \sa dsfmt_init_by_array()
528 */
529inline static void dsfmt_gv_init_by_array(uint32_t init_key[], int key_length) {
530 dsfmt_init_by_array(&dsfmt_global_data, init_key, key_length);
531}
532
533#if !defined(DSFMT_DO_NOT_USE_OLD_NAMES)
534DSFMT_PRE_INLINE const char *get_idstring(void) DSFMT_PST_INLINE;
535DSFMT_PRE_INLINE int get_min_array_size(void) DSFMT_PST_INLINE;
536DSFMT_PRE_INLINE void init_gen_rand(uint32_t seed) DSFMT_PST_INLINE;
537DSFMT_PRE_INLINE void init_by_array(uint32_t init_key[], int key_length)
538 DSFMT_PST_INLINE;
539DSFMT_PRE_INLINE double genrand_close1_open2(void) DSFMT_PST_INLINE;
540DSFMT_PRE_INLINE double genrand_close_open(void) DSFMT_PST_INLINE;
541DSFMT_PRE_INLINE double genrand_open_close(void) DSFMT_PST_INLINE;
542DSFMT_PRE_INLINE double genrand_open_open(void) DSFMT_PST_INLINE;
543DSFMT_PRE_INLINE void fill_array_open_close(double array[], int size)
544 DSFMT_PST_INLINE;
545DSFMT_PRE_INLINE void fill_array_close_open(double array[], int size)
546 DSFMT_PST_INLINE;
547DSFMT_PRE_INLINE void fill_array_open_open(double array[], int size)
548 DSFMT_PST_INLINE;
549DSFMT_PRE_INLINE void fill_array_close1_open2(double array[], int size)
550 DSFMT_PST_INLINE;
551
552/*
553 * This function is just the same as dsfmt_get_idstring().
554 * @return id string.
555 * see also \sa dsfmt_get_idstring()
556 */
557inline static const char *get_idstring(void) {
558 return dsfmt_get_idstring();
559}
560
561/*
562 * This function is just the same as dsfmt_get_min_array_size().
563 * @return minimum size of array used for fill_array functions.
564 * see also \sa dsfmt_get_min_array_size()
565 */
566inline static int get_min_array_size(void) {
567 return dsfmt_get_min_array_size();
568}
569
570/*
571 * This function is just the same as dsfmt_gv_init_gen_rand().
572 * @param seed a 32-bit integer used as the seed.
573 * see also \sa dsfmt_gv_init_gen_rand(), \sa dsfmt_init_gen_rand().
574 */
575inline static void init_gen_rand(uint32_t seed) {
576 dsfmt_gv_init_gen_rand(seed);
577}
578
579/*
580 * This function is just the same as dsfmt_gv_init_by_array().
581 * @param init_key the array of 32-bit integers, used as a seed.
582 * @param key_length the length of init_key.
583 * see also \sa dsfmt_gv_init_by_array(), \sa dsfmt_init_by_array().
584 */
585inline static void init_by_array(uint32_t init_key[], int key_length) {
586 dsfmt_gv_init_by_array(init_key, key_length);
587}
588
589/*
590 * This function is just the same as dsfmt_gv_genrand_close1_open2().
591 * @return double precision floating point number.
592 * see also \sa dsfmt_genrand_close1_open2() \sa
593 * dsfmt_gv_genrand_close1_open2()
594 */
595inline static double genrand_close1_open2(void) {
596 return dsfmt_gv_genrand_close1_open2();
597}
598
599/*
600 * This function is just the same as dsfmt_gv_genrand_close_open().
601 * @return double precision floating point number.
602 * see also \sa dsfmt_genrand_close_open() \sa
603 * dsfmt_gv_genrand_close_open()
604 */
605inline static double genrand_close_open(void) {
606 return dsfmt_gv_genrand_close_open();
607}
608
609/*
610 * This function is just the same as dsfmt_gv_genrand_open_close().
611 * @return double precision floating point number.
612 * see also \sa dsfmt_genrand_open_close() \sa
613 * dsfmt_gv_genrand_open_close()
614 */
615inline static double genrand_open_close(void) {
616 return dsfmt_gv_genrand_open_close();
617}
618
619/*
620 * This function is just the same as dsfmt_gv_genrand_open_open().
621 * @return double precision floating point number.
622 * see also \sa dsfmt_genrand_open_open() \sa
623 * dsfmt_gv_genrand_open_open()
624 */
625inline static double genrand_open_open(void) {
626 return dsfmt_gv_genrand_open_open();
627}
628
629/*
630 * This function is juset the same as dsfmt_gv_fill_array_open_close().
631 * @param array an array where pseudorandom numbers are filled
632 * by this function.
633 * @param size the number of pseudorandom numbers to be generated.
634 * see also \sa dsfmt_gv_fill_array_open_close(), \sa
635 * dsfmt_fill_array_close1_open2(), \sa
636 * dsfmt_gv_fill_array_close1_open2()
637 */
638inline static void fill_array_open_close(double array[], int size) {
639 dsfmt_gv_fill_array_open_close(array, size);
640}
641
642/*
643 * This function is juset the same as dsfmt_gv_fill_array_close_open().
644 * @param array an array where pseudorandom numbers are filled
645 * by this function.
646 * @param size the number of pseudorandom numbers to be generated.
647 * see also \sa dsfmt_gv_fill_array_close_open(), \sa
648 * dsfmt_fill_array_close1_open2(), \sa
649 * dsfmt_gv_fill_array_close1_open2()
650 */
651inline static void fill_array_close_open(double array[], int size) {
652 dsfmt_gv_fill_array_close_open(array, size);
653}
654
655/*
656 * This function is juset the same as dsfmt_gv_fill_array_open_open().
657 * @param array an array where pseudorandom numbers are filled
658 * by this function.
659 * @param size the number of pseudorandom numbers to be generated.
660 * see also \sa dsfmt_gv_fill_array_open_open(), \sa
661 * dsfmt_fill_array_close1_open2(), \sa
662 * dsfmt_gv_fill_array_close1_open2()
663 */
664inline static void fill_array_open_open(double array[], int size) {
665 dsfmt_gv_fill_array_open_open(array, size);
666}
667
668/*
669 * This function is juset the same as dsfmt_gv_fill_array_close1_open2().
670 * @param array an array where pseudorandom numbers are filled
671 * by this function.
672 * @param size the number of pseudorandom numbers to be generated.
673 * see also \sa dsfmt_fill_array_close1_open2(), \sa
674 * dsfmt_gv_fill_array_close1_open2()
675 */
676inline static void fill_array_close1_open2(double array[], int size) {
677 dsfmt_gv_fill_array_close1_open2(array, size);
678}
679#endif /* DSFMT_DO_NOT_USE_OLD_NAMES */
680
681typedef dsfmt_t ytRNG_dSFMT;
682
692#ifdef DOXY
694#else
695inline static ytRNG_dSFMT * ytRNG_dSFMT_new(void){
696 ytRNG_dSFMT * dsfmt = malloc(sizeof(ytRNG_dSFMT));
697 dsfmt_chk_init_gen_rand(dsfmt, 0, DSFMT_MEXP);
698 return dsfmt;
699}
700#endif /* DOXY */
701/* ytRNG_dSFMT_new() ======================================================= */
702
708#ifdef DOXY
709void ytRNG_dSFMT_delete(void * dsfmt);
710#else
711inline static void ytRNG_dSFMT_delete(void * dsfmt){
712 free(dsfmt);
713}
714#endif /* DOXY */
715/* ytRNG_dSFMT_delete() ==================================================== */
716
717/*\brief Initializes dSFMT, a double precision pseudo
718 * random number generator.
719 *
720 *\param dsfmt pointer returned by ytRNG_dSFMT_dSFMT_new().
721 *\param seed random seed.
722 *
723 *\ingroup ytRNG_dSFMT */
724#ifdef DOXY
725void ytRNG_dSFMT_init(ytRNG_dSFMT * dsfmt, uint32_t seed);
726#else
727static inline void ytRNG_dSFMT_init(ytRNG_dSFMT * dsfmt, uint32_t seed) {
728 dsfmt_chk_init_gen_rand(dsfmt, seed, DSFMT_MEXP);
729}
730#endif /* DOXY */
731/* ytRNG_dSFMT_init() ====================================================== */
732
737#ifdef DOXY
739#else
740INLINE ytRNG_dSFMT * ytRNG_dSFMT_new_init(uint32_t seed){
741 ytRNG_dSFMT * dsfmt = malloc(sizeof(ytRNG_dSFMT));
742 dsfmt_chk_init_gen_rand(dsfmt, seed, DSFMT_MEXP);
743 return dsfmt;
744}
745#endif /* DOXY */
746/* ytRNG_dSFMT_new_init() ================================================== */
747
757#ifdef DOXY
759#else
760static inline double ytRNG_dSFMT_close_open(ytRNG_dSFMT * dsfmt){
761 return dsfmt_genrand_close1_open2(dsfmt) - 1.0;
762}
763#endif /* DOXY */
764/* ytRNG_dSFMT_close_open() ================================================ */
765
766#define ytRNG_dSFMT_close_open_array(dsfmt, array, size) \
767 dsfmt_fill_array_close_open(dsfmt, array, size);
768
769#define ytRNG_dSFMT_uint32(dsfmt) dsfmt_genrand_uint32(dsfmt)
770
771#endif /* __YTLIB_RNG_DSFMT_H */
ytRNG_dSFMT * ytRNG_dSFMT_new()
Generates an instance for dSFMT random number generator.
double ytRNG_dSFMT_close_open(ytRNG_dSFMT *dsfmt)
Generates a double precision pseudo random number ranging [0,1).
ytRNG_dSFMT * ytRandom_dSFMT_new_init(uint32_t seed)
Generates an instance for dSFMT random number generator.
void ytRNG_dSFMT_delete(void *dsfmt)
Deletes the dSFMT random number generator instance.
Definition ytRNG_dSFMT.h:220
Definition ytRNG_dSFMT.h:209