Skip to content

test(crypto): make the numeric() distribution test non-flaky - #81

Merged
ExorTek merged 1 commit into
masterfrom
test/crypto-numeric-distribution
Oct 24, 2026
Merged

ExorTek merged 1 commit into
masterfrom
test/crypto-numeric-distribution

Conversation

@ExorTek

@ExorTek ExorTek commented Oct 24, 2026

Copy link
Copy Markdown
Owner

What / why

packages/crypto/tests/random/numeric.test.js turned master CI red after #79 merged (digit 2: count=9696, deviation=0.0304). The test allowed each digit 3% deviation over 100k draws, which is only ~3σ, so a healthy generator failed it on about 1-2% of runs. Nothing in the merged change touched @exortek/crypto.

Widening the bound alone would stop the test catching the modulo bias it exists for (~2% per digit), so it is now a Pearson chi-squared test over 1M digits (9 degrees of freedom, threshold 42.6 → false-positive rate 1e-6). A byte % 10 generator scores ~400 and still fails. 20/20 local runs pass.

Which package(s)?

  • @exortek/crypto (tests only)

Type of change

  • 🧹 Chore / refactor / lint / build

Checklist

  • Tests added / updated for the change
  • Changeset — not needed, no runtime change

The distribution test allowed each digit 3% deviation over 100k draws.
That is only ~3 standard deviations, so a healthy generator failed it on
roughly 1-2% of runs — it turned master CI red (digit 2 at 3.04%). Simply
widening the bound would stop it catching the modulo bias it exists
for (~2% per digit).

It is now a Pearson chi-squared test over 1M digits (9 dof, threshold
42.6 ⇒ false-positive rate 1e-6). A byte % 10 generator scores ~400 and
still fails.
Copilot AI balanced review requested due to automatic review settings October 24, 2026 13:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@ExorTek
ExorTek merged commit 77fd5d9 into master Oct 24, 2026
2 checks passed
@ExorTek
ExorTek deleted the test/crypto-numeric-distribution branch October 24, 2026 13:37
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