Repository navigation
Merged
Conversation
…ver a Random trait (#2279, D162) std.random fixed its results at i32 (`next_i32`, `range_i32`, plus `range_isize`): `range_i32(97, 123) as u8` at a byte consumer, and an i64 interval (`range(0, 1 << 40)`) could not be drawn at all. Now `next[T: Random]() -> T` and `range[T: Random](lo: T, hi: T) -> T` take the type from the use (a typed binding or parameter) or the bounds; a generic result binds from its demand (Law 2), so no new compiler mechanism is needed. `Random` is implemented for every integer type up to 64 bits and for f32 and f64, each through one 64-bit helper (signed_in / unsigned_in over the two's-complement span, unit() for floats), so no arithmetic trait is required; a user type becomes drawable by implementing it. `seed` takes a u64 (D114). The i32 helpers are deleted (Law 9): List.shuffle and the one-liner documents call `range`, and the documents drop their `as u8`. Test: behav_2279_random_draws_the_demanded_type (an i64 bound drawing past the i32 range, a u8 parameter, i8 and u16 bindings, f64 and f32 ranges, empty ranges, a repeated seed). behav_list_stable_sort and test/complexity/stdlib.w (shuffle) pass on stage1; the documents' one-liners run. Delegated under D98 as D162 (brief on #2279, 80%).
ehartford
marked this pull request as ready for review
October 26, 2026 08:24
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.
std.random fixed its results at i32 (
next_i32,range_i32, plusrange_isize):range_i32(97, 123) as u8at a byte consumer, and an i64interval (
range(0, 1 << 40)) could not be drawn at all.Now
next[T: Random]() -> Tandrange[T: Random](lo: T, hi: T) -> Ttake the type from the use (a typed binding or parameter) or the bounds;
a generic result binds from its demand (Law 2), so no new compiler
mechanism is needed.
Randomis implemented for every integer type up to64 bits and for f32 and f64, each through one 64-bit helper (signed_in /
unsigned_in over the two's-complement span, unit() for floats), so no
arithmetic trait is required; a user type becomes drawable by
implementing it.
seedtakes a u64 (D114). The i32 helpers are deleted(Law 9): List.shuffle and the one-liner documents call
range, and thedocuments drop their
as u8.Test: behav_2279_random_draws_the_demanded_type (an i64 bound drawing
past the i32 range, a u8 parameter, i8 and u16 bindings, f64 and f32
ranges, empty ranges, a repeated seed). behav_list_stable_sort and
test/complexity/stdlib.w (shuffle) pass on stage1; the documents'
one-liners run.
Delegated under D98 as D162 (brief on #2279, 80%).
Closes #2279