Skip to content

v1.1.1

Latest

Choose a tag to compare

@enetx enetx released this 10 Aug 11:30
feat!: make every rand function generic over its numeric arguments

Integer parameters accept any integer type and float parameters any float
type; the result follows the argument's type where one exists:
RangeInclusive[T] returns T for the full domain of any width, signed or
unsigned, without overflow or bias; Perm[T] returns Slice[T]; Uniform[T]
returns T; Chance[T] takes any float; Choices/Sample take k of any integer
type; Bytes/String/SecureBytes/SecureString take length of any integer type.

BREAKING CHANGES:
- calls with g-typed arguments compile unchanged (T infers to g.Int/g.Float),
  but untyped constants now infer their default types: rand.Perm(5) yields
  Slice[int] (was Slice[g.Int]) and rand.Uniform(1.5, 2.0) returns float64
  (was g.Float) — pass g.Int(5) / g.Float(1.5) to keep g-typed results

Deliberately NOT generic:
- zero-argument Float/NormFloat/Bool — with nothing to infer from, a type
  parameter would force explicit instantiation at every call site
- letters stays ...g.String — an empty variadic cannot infer a ~string
  parameter (rand.String(10) would not compile; verified against the
  compiler), and untyped string literals convert implicitly anyway

tests/rand: TestGenericArguments pins inference across uint8/int8/uint16/
int32/int64/uint/float32/g.Float call shapes.