• R/O
• HTTP
• SSH
• HTTPS

hengband: コミット

コミットメタ情報

リビジョン 4e4ae59c8e5a9e69896117b3cf7b7c46ddc2d5a9 (tree) 2016-02-25 13:11:00 Habu Habu

RNGをxorshift+に変更

差分

--- a/src/z-rand.c
+++ b/src/z-rand.c
 @@ -85,22 +85,22 @@ static void Rand_Xorshift_seed(u32b seed, u32b* state) 85 85 } 86 86 87 87 /* 88 - * Xorshift Algorithm 88 + * Xorshift128plus Algorithm 89 89 */ 90 -static u32b Rand_Xorshift(u32b* state) 90 +static u64b Rand_Xorshift128plus_next(u64b* state0, u64b* state1) 91 91 { 92 - u32b t = state[0] ^ (state[0] << 11); 93 - 94 - state[0] = state[1]; 95 - state[1] = state[2]; 96 - state[2] = state[3]; 97 - 98 - state[3] = (state[3] ^ (state[3] >> 19)) ^ (t ^ (t >> 8)); 99 - 100 - return state[3]; 92 + u64b s1 = *state0; 93 + const u64b s0 = *state1; 94 + *state0 = s0; 95 + s1 ^= s1 << 23; 96 + s1 ^= s1 >> 17; 97 + s1 ^= s0; 98 + s1 ^= s0 >> 26; 99 + *state1 = s1; 100 + return s0 + s1; 101 101 } 102 102 103 -static const u32b Rand_Xorshift_max = 0xFFFFFFFF; 103 +static const u32b Rand_max = 0xFFFFFFFF; 104 104 105 105 /* 106 106 * Initialize the RNG using a new seed
 @@ -185,11 +185,11 @@ static s32b Rand_div_impl(s32b m, u32b* state) 185 185 /* Hack -- simple case */ 186 186 if (m <= 1) return (0); 187 187 188 - scaling = Rand_Xorshift_max / m; 188 + scaling = Rand_max / m; 189 189 past = scaling * m; 190 190 191 191 do { 192 - ret = Rand_Xorshift(state); 192 + ret = (u32b)(Rand_Xorshift128plus_next((u64b*)&state[0], (u64b*)&state[2]) >> 32); 193 193 } while (ret >= past); 194 194 195 195 return ret / scaling;