fix(dummies): draw decimal fractions from all 96 mantissa bits - #268
Merged
Conversation
AnyDecimal built its fraction from three non-negative Random.Next() draws over the full 96-bit mantissa denominator. Each limb's top bit was therefore pinned to zero, so the fraction never exceeded ~0.5 and every candidate fell in [min, mid): the upper half of every range — and the inclusive maximum documented on Between — was unreachable. Fill all three mantissa limbs from NextBytes, yielding a genuinely uniform fraction over the whole [0, 1] scale, and correct the stale comment. Seeded reproducibility is preserved: the same seed still replays the same sequence within a version. Add a seeded reachability test proving both halves, and a value near the inclusive maximum, are observed. Refs: #206 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019Z8qWCLG88eE9brd7YwawW
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AnyDecimalnever generated the upper half of any range. The sampling fraction was built from three non-negativeRandom.Next()draws over the full 96-bit mantissa denominator, so each limb's top bit stayed zero and the fraction capped near0.5; every candidate fell in[min, mid)and the inclusive maximum documented onBetweenwas unreachable. This fills all 96 mantissa bits so the fraction is uniform over[0, 1]and the whole range — up to the inclusive maximum — is reachable.Type of change
Changes
random.NextBytes+ threeBitConverter.ToInt32, replacing the three non-negativeRandom.Next()draws that pinned each limb's top bit to zero (DecimalIntervalSpec.Generate).[0, 1)comment to describe the real[0, 1]construction.AnyContinuousTests.DecimalBetweenReachesBothHalves) asserting that both halves of a range — and a value near the inclusive maximum — are observed.Testing
dotnet build FirstClassErrors.slndotnet test FirstClassErrors.slnFirstClassErrors.Analyzers.UnitTests)Full solution: build clean (0 warnings);
dotnet test FirstClassErrors.slnreports 0 failures across every test project, includingFirstClassErrors.Analyzers.UnitTests(85) andDummies.UnitTests(223) with the new reachability test.Documentation
doc/updateddoc/handwritten/for-users/README.fr.md) updated if user-facing behavior changedThe documented contract —
Betweenyields values in the inclusive[minimum, maximum]range — does not change; this fix makes it hold. Seeded reproducibility within a version is preserved.Architecture decisions
Proposed: ADR-____Checked against the ADR base: this is a sampling-construction bug fix, not a lasting decision. It stays compliant with ADR-0026 (single engine, single seed scope) — the engine and seed scope are unchanged.
Related issues
Closes #206
🤖 Generated with Claude Code
https://claude.ai/code/session_019Z8qWCLG88eE9brd7YwawW
Generated by Claude Code