Skip to content

Add Random#split and #split_internal API for splittable PRNGs#16342

Merged
straight-shoota merged 2 commits intocrystal-lang:masterfrom
ysbaddaden:feature/add-random-split
Nov 9, 2025
Merged

Add Random#split and #split_internal API for splittable PRNGs#16342
straight-shoota merged 2 commits intocrystal-lang:masterfrom
ysbaddaden:feature/add-random-split

Conversation

@ysbaddaden
Copy link
Collaborator

@ysbaddaden ysbaddaden commented Nov 7, 2025

Adds a couple methods to formalize the API for splitting a Random instance:

  • Random#split: splits the instance by allocating a new instance.
  • #split_internal: splits the instance into an allocated instance (for example ReferenceStorage(T)).

I initially wanted a #split! method with no argument, but we need access to both instances to avoid splits (and re-splits of splits) to end up sharing the same sequences.

Extracted from #16174 and adapted with usages in the random shard (SplittableRandom, XoShiRo).

- #split: splits the instance by allocating a new instance
- #split_internal: splits the instance using an allocated instance, for
  example with ReferenceStorage(T)
@straight-shoota straight-shoota added this to the 1.19.0 milestone Nov 7, 2025
@straight-shoota straight-shoota merged commit 98bf671 into crystal-lang:master Nov 9, 2025
40 checks passed
@ysbaddaden ysbaddaden deleted the feature/add-random-split branch November 10, 2025 13:01
ysbaddaden added a commit to ysbaddaden/crystal that referenced this pull request Dec 4, 2025
ysbaddaden added a commit to ysbaddaden/crystal that referenced this pull request Dec 11, 2025
straight-shoota pushed a commit that referenced this pull request Dec 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants