SFMT.h

Go to the documentation of this file.
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) || defined(__BORLANDC__)
00039   typedef unsigned int uint32_t;
00040   typedef unsigned __int64 uint64_t;
00041   #define inline __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) || defined(__BORLANDC__)
00051     #define PRIu64 "I64u"
00052     #define PRIx64 "I64x"
00053   #else
00054     #define PRIu64 "llu"
00055     #define PRIx64 "llx"
00056   #endif
00057 #endif
00058 
00059 #if defined(__GNUC__)
00060 #define ALWAYSINLINE __attribute__((always_inline))
00061 #else
00062 #define ALWAYSINLINE
00063 #endif
00064 
00065 #if defined(_MSC_VER)
00066   #if _MSC_VER >= 1200
00067     #define PRE_ALWAYS __forceinline
00068   #else
00069     #define PRE_ALWAYS inline
00070   #endif
00071 #else
00072   #define PRE_ALWAYS inline
00073 #endif
00074 
00075 uint32_t gen_rand32(void);
00076 uint64_t gen_rand64(void);
00077 void fill_array32(uint32_t *array, int size);
00078 void fill_array64(uint64_t *array, int size);
00079 void init_gen_rand(uint32_t seed);
00080 void init_by_array(uint32_t *init_key, int key_length);
00081 const char *get_idstring(void);
00082 int get_min_array_size32(void);
00083 int get_min_array_size64(void);
00084 
00085 /* These real versions are due to Isaku Wada */
00087 inline static double to_real1(uint32_t v)
00088 {
00089     return v * (1.0/4294967295.0); 
00090     /* divided by 2^32-1 */ 
00091 }
00092 
00094 inline static double genrand_real1(void)
00095 {
00096     return to_real1(gen_rand32());
00097 }
00098 
00100 inline static double to_real2(uint32_t v)
00101 {
00102     return v * (1.0/4294967296.0); 
00103     /* divided by 2^32 */
00104 }
00105 
00107 inline static double genrand_real2(void)
00108 {
00109     return to_real2(gen_rand32());
00110 }
00111 
00113 inline static double to_real3(uint32_t v)
00114 {
00115     return (((double)v) + 0.5)*(1.0/4294967296.0); 
00116     /* divided by 2^32 */
00117 }
00118 
00120 inline static double genrand_real3(void)
00121 {
00122     return to_real3(gen_rand32());
00123 }
00127 inline static double to_res53(uint64_t v) 
00128 { 
00129     return v * (1.0/18446744073709551616.0L);
00130 }
00131 
00134 inline static double to_res53_mix(uint32_t x, uint32_t y) 
00135 { 
00136     return to_res53(x | ((uint64_t)y << 32));
00137 }
00138 
00141 inline static double genrand_res53(void) 
00142 { 
00143     return to_res53(gen_rand64());
00144 } 
00145 
00149 inline static double genrand_res53_mix(void) 
00150 { 
00151     uint32_t x, y;
00152 
00153     x = gen_rand32();
00154     y = gen_rand32();
00155     return to_res53_mix(x, y);
00156 } 
00157 #endif

Generated on Sat Oct 6 12:14:32 2007 for SFMT by  doxygen 1.4.7