42#ifndef __YTLIB_RNG_DSFMT_H
43#define __YTLIB_RNG_DSFMT_H
48#define DSFMT_MEXP 19937
50#if defined __GNUC__ && !defined __GNUC_STDC_INLINE__ && !defined __GNUC_GNU_INLINE__
51# define __GNUC_GNU_INLINE__ 1
55# if __GNUC__ && !__GNUC_STDC_INLINE__
56# define INLINE extern inline
95#if !defined(DSFMT_MEXP)
97 #warning "DSFMT_MEXP is not defined. I assume DSFMT_MEXP is 19937."
99 #define DSFMT_MEXP 19937
109#define DSFMT_N ((DSFMT_MEXP - 128) / 104 + 1)
112#define DSFMT_N32 (DSFMT_N * 4)
115#define DSFMT_N64 (DSFMT_N * 2)
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
122# elif defined(_BYTE_ORDER) && defined(_BIG_ENDIAN)
123# if _BYTE_ORDER == _BIG_ENDIAN
124# define DSFMT_BIG_ENDIAN 1
126# elif defined(__BYTE_ORDER__) && defined(__BIG_ENDIAN__)
127# if __BYTE_ORDER__ == __BIG_ENDIAN__
128# define DSFMT_BIG_ENDIAN 1
130# elif defined(BYTE_ORDER) && defined(BIG_ENDIAN)
131# if BYTE_ORDER == BIG_ENDIAN
132# define DSFMT_BIG_ENDIAN 1
134# elif defined(__BIG_ENDIAN) || defined(_BIG_ENDIAN) \
135 || defined(__BIG_ENDIAN__) || defined(BIG_ENDIAN)
136# define DSFMT_BIG_ENDIAN 1
140#if defined(DSFMT_BIG_ENDIAN) && defined(__amd64)
141# undef DSFMT_BIG_ENDIAN
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
153# define inline __inline
157# include <inttypes.h>
159# if defined(__GNUC__)
160# define inline __inline__
168# if defined(_MSC_VER) || defined(__BORLANDC__)
169# define PRIu64 "I64u"
170# define PRIx64 "I64x"
178# define UINT64_C(v) (v ## ULL)
184#if defined(HAVE_ALTIVEC)
185# if !defined(__APPLE__)
190 vector
unsigned int s;
196#elif defined(HAVE_SSE2)
197# include <emmintrin.h>
221 w128_t status[DSFMT_N + 1];
227extern dsfmt_t dsfmt_global_data;
229extern const int dsfmt_global_mexp;
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);
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
249# define DSFMT_PRE_INLINE inline static
250# define DSFMT_PST_INLINE
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)
255DSFMT_PRE_INLINE
double dsfmt_genrand_close_open(
dsfmt_t *dsfmt)
257DSFMT_PRE_INLINE
double dsfmt_genrand_open_close(
dsfmt_t *dsfmt)
259DSFMT_PRE_INLINE
double dsfmt_genrand_open_open(
dsfmt_t *dsfmt)
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)
268DSFMT_PRE_INLINE
void dsfmt_gv_fill_array_close_open(
double array[],
int size)
270DSFMT_PRE_INLINE
void dsfmt_gv_fill_array_open_open(
double array[],
int size)
272DSFMT_PRE_INLINE
void dsfmt_gv_fill_array_close1_open2(
double array[],
int size)
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)
279DSFMT_PRE_INLINE
void dsfmt_init_by_array(
dsfmt_t *dsfmt, uint32_t init_key[],
280 int key_length) DSFMT_PST_INLINE;
290inline static uint32_t dsfmt_genrand_uint32(
dsfmt_t *dsfmt) {
292 uint64_t *psfmt64 = &dsfmt->status[0].u[0];
294 if (dsfmt->idx >= DSFMT_N64) {
295 dsfmt_gen_rand_all(dsfmt);
298 r = psfmt64[dsfmt->idx++] & 0xffffffffU;
311inline static double dsfmt_genrand_close1_open2(
dsfmt_t *dsfmt) {
313 double *psfmt64 = &dsfmt->status[0].d[0];
315 if (dsfmt->idx >= DSFMT_N64) {
316 dsfmt_gen_rand_all(dsfmt);
319 r = psfmt64[dsfmt->idx++];
330inline static uint32_t dsfmt_gv_genrand_uint32(
void) {
331 return dsfmt_genrand_uint32(&dsfmt_global_data);
341inline static double dsfmt_gv_genrand_close1_open2(
void) {
342 return dsfmt_genrand_close1_open2(&dsfmt_global_data);
353inline static double dsfmt_genrand_close_open(
dsfmt_t *dsfmt) {
354 return dsfmt_genrand_close1_open2(dsfmt) - 1.0;
364inline static double dsfmt_gv_genrand_close_open(
void) {
365 return dsfmt_gv_genrand_close1_open2() - 1.0;
376inline static double dsfmt_genrand_open_close(
dsfmt_t *dsfmt) {
377 return 2.0 - dsfmt_genrand_close1_open2(dsfmt);
387inline static double dsfmt_gv_genrand_open_close(
void) {
388 return 2.0 - dsfmt_gv_genrand_close1_open2();
399inline static double dsfmt_genrand_open_open(
dsfmt_t *dsfmt) {
400 double *dsfmt64 = &dsfmt->status[0].d[0];
406 if (dsfmt->idx >= DSFMT_N64) {
407 dsfmt_gen_rand_all(dsfmt);
410 r.d = dsfmt64[dsfmt->idx++];
422inline static double dsfmt_gv_genrand_open_open(
void) {
423 return dsfmt_genrand_open_open(&dsfmt_global_data);
437inline static void dsfmt_gv_fill_array_close1_open2(
double array[],
int size) {
438 dsfmt_fill_array_close1_open2(&dsfmt_global_data, array, size);
453inline static void dsfmt_gv_fill_array_open_close(
double array[],
int size) {
454 dsfmt_fill_array_open_close(&dsfmt_global_data, array, size);
469inline static void dsfmt_gv_fill_array_close_open(
double array[],
int size) {
470 dsfmt_fill_array_close_open(&dsfmt_global_data, array, size);
485inline static void dsfmt_gv_fill_array_open_open(
double array[],
int size) {
486 dsfmt_fill_array_open_open(&dsfmt_global_data, array, size);
495inline static void dsfmt_init_gen_rand(
dsfmt_t *dsfmt, uint32_t seed) {
496 dsfmt_chk_init_gen_rand(dsfmt, seed, DSFMT_MEXP);
505inline static void dsfmt_gv_init_gen_rand(uint32_t seed) {
506 dsfmt_init_gen_rand(&dsfmt_global_data, seed);
516inline static void dsfmt_init_by_array(
dsfmt_t *dsfmt, uint32_t init_key[],
518 dsfmt_chk_init_by_array(dsfmt, init_key, key_length, DSFMT_MEXP);
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);
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)
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)
545DSFMT_PRE_INLINE
void fill_array_close_open(
double array[],
int size)
547DSFMT_PRE_INLINE
void fill_array_open_open(
double array[],
int size)
549DSFMT_PRE_INLINE
void fill_array_close1_open2(
double array[],
int size)
557inline static const char *get_idstring(
void) {
558 return dsfmt_get_idstring();
566inline static int get_min_array_size(
void) {
567 return dsfmt_get_min_array_size();
575inline static void init_gen_rand(uint32_t seed) {
576 dsfmt_gv_init_gen_rand(seed);
585inline static void init_by_array(uint32_t init_key[],
int key_length) {
586 dsfmt_gv_init_by_array(init_key, key_length);
595inline static double genrand_close1_open2(
void) {
596 return dsfmt_gv_genrand_close1_open2();
605inline static double genrand_close_open(
void) {
606 return dsfmt_gv_genrand_close_open();
615inline static double genrand_open_close(
void) {
616 return dsfmt_gv_genrand_open_close();
625inline static double genrand_open_open(
void) {
626 return dsfmt_gv_genrand_open_open();
638inline static void fill_array_open_close(
double array[],
int size) {
639 dsfmt_gv_fill_array_open_close(array, size);
651inline static void fill_array_close_open(
double array[],
int size) {
652 dsfmt_gv_fill_array_close_open(array, size);
664inline static void fill_array_open_open(
double array[],
int size) {
665 dsfmt_gv_fill_array_open_open(array, size);
676inline static void fill_array_close1_open2(
double array[],
int size) {
677 dsfmt_gv_fill_array_close1_open2(array, size);
697 dsfmt_chk_init_gen_rand(dsfmt, 0, DSFMT_MEXP);
725void ytRNG_dSFMT_init(
ytRNG_dSFMT * dsfmt, uint32_t seed);
727static inline void ytRNG_dSFMT_init(
ytRNG_dSFMT * dsfmt, uint32_t seed) {
728 dsfmt_chk_init_gen_rand(dsfmt, seed, DSFMT_MEXP);
740INLINE
ytRNG_dSFMT * ytRNG_dSFMT_new_init(uint32_t seed){
742 dsfmt_chk_init_gen_rand(dsfmt, seed, DSFMT_MEXP);
761 return dsfmt_genrand_close1_open2(dsfmt) - 1.0;
766#define ytRNG_dSFMT_close_open_array(dsfmt, array, size) \
767 dsfmt_fill_array_close_open(dsfmt, array, size);
769#define ytRNG_dSFMT_uint32(dsfmt) dsfmt_genrand_uint32(dsfmt)
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