Skip to content

Add generic NumberSource<T> and NullableNumberSource<T> with min/max - #5

Merged
holonsoftFounder merged 1 commit into
mainfrom
feature/number-source
Sep 9, 2026
Merged

Add generic NumberSource<T> and NullableNumberSource<T> with min/max#5
holonsoftFounder merged 1 commit into
mainfrom
feature/number-source

Conversation

@holonsoftFounder

Copy link
Copy Markdown
Member

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, decimal
  • integers are drawn uniformly from the inclusive range: width computed in modular UInt128 arithmetic (exact for signed and unsigned up to 128 bit), Random.NextInt64 for widths below long.MaxValue, 16 random bytes with rejection sampling above that
  • floating point and decimal are interpolated as min * (1 - s) + max * s, which cannot overflow even for the whole range of the type (the existing DoubleSource() default produces infinity)
  • bounds are validated on construction and on SetMinMax/SetMin/SetMax: max below min, NaN and infinity throw ArgumentOutOfRangeException, the old range survives a failed change
  • NullableNumberSource<T> takes an explicit null creation threshold
  • existing IntegerSource, DecimalSource and friends untouched, defaults untouched, no stable sequence changed
  • README section and PackageReleaseNotes

Test plan

  • 25 new tests: range per type, whole-type ranges, both ends of short ranges, every byte value, rough uniformity for small ranges and for a range wider than long, min == max, validation, setters, nullable threshold, stable sequences, integration via Use<>(ctor args), Use<>(lambda), field, generation time Source(...)
  • dotnet build -c Release zero warnings
  • 707 tests green on net8, net9 and net10 (Windows)

🤖 Generated with Claude Code

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>
@holonsoftFounder
holonsoftFounder merged commit fb1d60f into main Sep 9, 2026
2 checks passed
@holonsoftFounder
holonsoftFounder deleted the feature/number-source branch September 9, 2026 06:56
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.

1 participant