00001
00031 #ifndef SFMT_H
00032 #define SFMT_H
00033
00034 #include <stdio.h>
00035
00036 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
00037 #include <inttypes.h>
00038 #elif defined(_MSC_VER)
00039 typedef unsigned int uint32_t;
00040 typedef unsigned long long uint64_t;
00041 #define inline
00042 #else
00043 #include <inttypes.h>
00044 #if defined(__GNUC__)
00045 #define inline __inline__
00046 #endif
00047 #endif
00048
00049 #ifndef PRIu64
00050 #if defined(_MSC_VER)
00051 #define PRIu64 "I64u"
00052 #define PRIx64 "I64x"
00053 #else
00054 #define PRIu64 "llu"
00055 #define PRIx64 "llx"
00056 #endif
00057 #endif
00058
00059 inline uint32_t gen_rand32(void);
00060 inline uint64_t gen_rand64(void);
00061 inline void fill_array32(uint32_t array[], int size);
00062 inline void fill_array64(uint64_t array[], int size);
00063 void init_gen_rand(uint32_t seed);
00064 void init_by_array(uint32_t init_key[], int key_length);
00065 char *get_idstring(void);
00066 int get_min_array_size32(void);
00067 int get_min_array_size64(void);
00068
00069
00071 inline static double to_real1(uint32_t v)
00072 {
00073 return v * (1.0/4294967295.0);
00074
00075 }
00076
00078 inline static double genrand_real1(void)
00079 {
00080 return to_real1(gen_rand32());
00081 }
00082
00084 inline static double to_real2(uint32_t v)
00085 {
00086 return v * (1.0/4294967296.0);
00087
00088 }
00089
00091 inline static double genrand_real2(void)
00092 {
00093 return to_real2(gen_rand32());
00094 }
00095
00097 inline static double to_real3(uint32_t v)
00098 {
00099 return (((double)v) + 0.5)*(1.0/4294967296.0);
00100
00101 }
00102
00104 inline static double genrand_real3(void)
00105 {
00106 return to_real3(gen_rand32());
00107 }
00111 inline static double to_res53(uint64_t v)
00112 {
00113 return v * (1.0/18446744073709551616.0L);
00114 }
00115
00117 inline static double genrand_res53(void)
00118 {
00119 return to_res53(gen_rand64());
00120 }
00121 #endif