• R/O
  • HTTP
  • SSH
  • HTTPS

hengband: コミット

変愚蛮怒のメインリポジトリです


コミットメタ情報

リビジョン4e4ae59c8e5a9e69896117b3cf7b7c46ddc2d5a9 (tree)
日時2016-02-25 13:11:00
作者Habu <habu@user...>
コミッター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)
8585 }
8686
8787 /*
88- * Xorshift Algorithm
88+ * Xorshift128plus Algorithm
8989 */
90-static u32b Rand_Xorshift(u32b* state)
90+static u64b Rand_Xorshift128plus_next(u64b* state0, u64b* state1)
9191 {
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;
101101 }
102102
103-static const u32b Rand_Xorshift_max = 0xFFFFFFFF;
103+static const u32b Rand_max = 0xFFFFFFFF;
104104
105105 /*
106106 * Initialize the RNG using a new seed
@@ -185,11 +185,11 @@ static s32b Rand_div_impl(s32b m, u32b* state)
185185 /* Hack -- simple case */
186186 if (m <= 1) return (0);
187187
188- scaling = Rand_Xorshift_max / m;
188+ scaling = Rand_max / m;
189189 past = scaling * m;
190190
191191 do {
192- ret = Rand_Xorshift(state);
192+ ret = (u32b)(Rand_Xorshift128plus_next((u64b*)&state[0], (u64b*)&state[2]) >> 32);
193193 } while (ret >= past);
194194
195195 return ret / scaling;
旧リポジトリブラウザで表示