From 880fdeca43b2da64b9ffe1bef30a8b4e5a938d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Wed, 2 Jul 2025 09:10:19 -0400 Subject: [PATCH] Fix bug in PCG implementation in wasi.cpp --- binding-sandbox/wasi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binding-sandbox/wasi.cpp b/binding-sandbox/wasi.cpp index 1944ffee..3f65e415 100644 --- a/binding-sandbox/wasi.cpp +++ b/binding-sandbox/wasi.cpp @@ -1252,7 +1252,7 @@ extern "C" uint32_t w2c_wasi__snapshot__preview1_random_get(wasi_t *wasi, wasm_p wasi->prng_state = wasi->prng_state * (uint64_t)6364136223846793005U + (uint64_t)1442695040888963407U; // Advance state before computing output to improve instruction-level parallelism uint32_t xsh = (state ^ (state >> 18U)) >> 27U; uint32_t rot = state >> 59U; - uint32_t out = xsh >> rot | xsh << ((uint32_t)32U - rot); + uint32_t out = xsh >> rot | xsh << ((uint32_t)31U - rot); #ifdef MKXPZ_BIG_ENDIAN // Byte swap the output on big-endian machines to preserve state state compatibility across machines with different endiannesses std::reverse_copy((uint8_t *)&out, (uint8_t *)&out + 4, wasi->prng_buffer);