Mercurial > vba-linux
view src/SFMT/SFMT.h @ 30:48369c6aeaa0 compile-milestone
brought prof package in
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sun, 04 Mar 2012 22:32:01 -0600 |
parents | f9f4f1b99eed |
children |
line wrap: on
line source
1 /**2 * @file SFMT.h3 *4 * @brief SIMD oriented Fast Mersenne Twister(SFMT) pseudorandom5 * number generator6 *7 * @author Mutsuo Saito (Hiroshima University)8 * @author Makoto Matsumoto (Hiroshima University)9 *10 * Copyright (C) 2006, 2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima11 * University. All rights reserved.12 *13 * The new BSD License is applied to this software.14 * see LICENSE.txt15 *16 * @note We assume that your system has inttypes.h. If your system17 * 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 * @verbatim20 typedef unsigned int uint32_t21 typedef unsigned long long uint64_t22 #define PRIu64 "llu"23 #define PRIx64 "llx"24 @endverbatim25 * uint32_t must be exactly 32-bit unsigned integer type (no more, no26 * less), and uint64_t must be exactly 64-bit unsigned integer type.27 * PRIu64 and PRIx64 are used for printf function to print 64-bit28 * unsigned int and 64-bit unsigned int in hexadecimal format.29 */31 #ifndef SFMT_H32 #define SFMT_H34 #include <stdio.h>36 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)37 #include <inttypes.h>38 #elif defined(_MSC_VER) || defined(__BORLANDC__)39 typedef unsigned int uint32_t;40 typedef unsigned __int64 uint64_t;41 #define inline __inline42 #else43 #include <inttypes.h>44 #if defined(__GNUC__)45 #define inline __inline__46 #endif47 #endif49 #ifndef PRIu6450 #if defined(_MSC_VER) || defined(__BORLANDC__)51 #define PRIu64 "I64u"52 #define PRIx64 "I64x"53 #else54 #define PRIu64 "llu"55 #define PRIx64 "llx"56 #endif57 #endif59 #if defined(__GNUC__)60 #define ALWAYSINLINE __attribute__((always_inline))61 #else62 #define ALWAYSINLINE63 #endif65 #if defined(_MSC_VER)66 #if _MSC_VER >= 120067 #define PRE_ALWAYS __forceinline68 #else69 #define PRE_ALWAYS inline70 #endif71 #else72 #define PRE_ALWAYS inline73 #endif75 #if defined(__cplusplus) || defined(c_plusplus)76 //extern "C" {77 #endif79 uint32_t gen_rand32(void);80 uint64_t gen_rand64(void);81 void fill_array32(uint32_t *array, int size);82 void fill_array64(uint64_t *array, int size);83 void init_gen_rand(uint32_t seed);84 void init_by_array(uint32_t *init_key, int key_length);85 const char *get_idstring(void);86 int get_min_array_size32(void);87 int get_min_array_size64(void);89 #if defined(__cplusplus) || defined(c_plusplus)90 //} // end extern91 #endif93 /* These real versions are due to Isaku Wada */94 /** generates a random number on [0,1]-real-interval */95 inline static double to_real1(uint32_t v)96 {97 return v * (1.0/4294967295.0);98 /* divided by 2^32-1 */99 }101 /** generates a random number on [0,1]-real-interval */102 inline static double genrand_real1(void)103 {104 return to_real1(gen_rand32());105 }107 /** generates a random number on [0,1)-real-interval */108 inline static double to_real2(uint32_t v)109 {110 return v * (1.0/4294967296.0);111 /* divided by 2^32 */112 }114 /** generates a random number on [0,1)-real-interval */115 inline static double genrand_real2(void)116 {117 return to_real2(gen_rand32());118 }120 /** generates a random number on (0,1)-real-interval */121 inline static double to_real3(uint32_t v)122 {123 return (((double)v) + 0.5)*(1.0/4294967296.0);124 /* divided by 2^32 */125 }127 /** generates a random number on (0,1)-real-interval */128 inline static double genrand_real3(void)129 {130 return to_real3(gen_rand32());131 }132 /** These real versions are due to Isaku Wada */134 /** generates a random number on [0,1) with 53-bit resolution*/135 inline static double to_res53(uint64_t v)136 {137 return v * (1.0/18446744073709551616.0L);138 }140 /** generates a random number on [0,1) with 53-bit resolution from two141 * 32 bit integers */142 inline static double to_res53_mix(uint32_t x, uint32_t y)143 {144 return to_res53(x | ((uint64_t)y << 32));145 }147 /** generates a random number on [0,1) with 53-bit resolution148 */149 inline static double genrand_res53(void)150 {151 return to_res53(gen_rand64());152 }154 /** generates a random number on [0,1) with 53-bit resolution155 using 32bit integer.156 */157 inline static double genrand_res53_mix(void)158 {159 uint32_t x, y;161 x = gen_rand32();162 y = gen_rand32();163 return to_res53_mix(x, y);164 }165 #endif