Skip to content

Conversation

@MineCake147E
Copy link
Contributor

What

#731 を実装した際、Float64ArrayUint8Array() constructorの第一引数に指定した場合の仕様の理解が間違っており、numで与えられたシード値が意図せず& 255されてしまっていました。
本修正では、TypedArray.prototype.bufferを取る事により、#731 の実装時に意図したように、numberの内部表現をそのままseedとして使用することにより、3.03.0000000000000004で異なる出力を得られるようになります。
これにより、全く同じseedでも、修正前と修正後で出力が変わります。
また、本修正後も旧来の動作を再現できるよう、関数Math:gen_rngoptions.chacha20NumberSeedLegacyBehaviour(デフォルト:false)にtrueを指定した場合、修正前の動作をする機能を追加しました。

<: (Math:gen_rng(0)(0, 4503599627370495)).to_hex()
<: (Math:gen_rng(0.000001)(0, 4503599627370495)).to_hex()
<: (Math:gen_rng(256.000001)(0, 4503599627370495)).to_hex()

Before:

"b3f8c68b3d7e0"
"b3f8c68b3d7e0"
"b3f8c68b3d7e0"
(null)

After:

"53b92953000f2"
"29f33b8f9931b"
"1ed54e7a15574"
(null)

Why

某Playの出力が複数日連続で同一となった事により発覚。
algorithmrc4を指定した場合と挙動が大きく異なるため。

Additional info (optional)

Workaround for versions before this fix

  • seedを与える前に.to_str()等でstringに変換する

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/utils/random/genrng.ts 80.00% 2 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Files with missing lines Coverage Δ
src/interpreter/lib/math.ts 64.64% <100.00%> (ø)
src/utils/random/genrng.ts 57.44% <80.00%> (+5.36%) ⬆️

... and 29 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants