Add generic NumberSource<T> and NullableNumberSource<T> with min/max - #5
Merged
Conversation
One source for every built-in numeric type on INumber<T> and IMinMaxValue<T>: integers up to 128 bit are drawn uniformly from the inclusive range (width in modular UInt128 arithmetic, rejection sampling above long.MaxValue), floating point and decimal are interpolated between the bounds without overflowing even for the whole range of the type. Bounds are validated (max below min, NaN, infinity throw ArgumentOutOfRangeException). The nullable variant takes an explicit null creation threshold. Unit and integration tests, README and release notes. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
4 tasks
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
NumberSource<T>/NullableNumberSource<T>for every built-in numeric type (T : INumber<T>, IMinMaxValue<T>): integers up to 128 bit incl.Int128,UInt128,nint,char;float,double,Half,decimalUInt128arithmetic (exact for signed and unsigned up to 128 bit),Random.NextInt64for widths belowlong.MaxValue, 16 random bytes with rejection sampling above thatmin * (1 - s) + max * s, which cannot overflow even for the whole range of the type (the existingDoubleSource()default produces infinity)SetMinMax/SetMin/SetMax: max below min, NaN and infinity throwArgumentOutOfRangeException, the old range survives a failed changeNullableNumberSource<T>takes an explicit null creation thresholdIntegerSource,DecimalSourceand friends untouched, defaults untouched, no stable sequence changedTest plan
long, min == max, validation, setters, nullable threshold, stable sequences, integration viaUse<>(ctor args),Use<>(lambda), field, generation timeSource(...)dotnet build -c Releasezero warnings🤖 Generated with Claude Code