mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 09:44:24 +00:00
Add WorldRandom.pick and shuffle so stages need no JDK random APIs
pick(items) is items.get(nextInt(items.size())) and throws on an empty list. shuffle(items) is Fisher-Yates from the last index down, swapping i with nextInt(i + 1). RandomAccess lists swap through List.set; other lists are shuffled in an array copy and written back through their ListIterator, with the same result. Both are pinned to the Python reference, including draw counts.
This commit is contained in:
1 parent
525c372fc5
commit
8b7accd19d
5 files changed
+193
-7
No files matched your search
@@ -57,8 +57,9 @@ module may still condition its stages on it, as moss does on `iris:snow`.
|
||||
Stages and object generators draw from `com.volmit.random.WorldRandom`, an IrisApi type whose every
|
||||
method is defined and pinned by tests, so the same seed gives the same world on every JDK. It is
|
||||
SplitMix64 with `nextInt`, `nextLong` and `nextDouble` in plain, bounded and `origin, bound` forms,
|
||||
plus `nextBoolean`, `nextFloat`, `nextGaussian` and `chance(probability)`. It does not implement
|
||||
`java.util.random.RandomGenerator`, whose default methods the JDK may change. Bounded integers are
|
||||
plus `nextBoolean`, `nextFloat`, `nextGaussian`, `chance(probability)`, `pick(list)` and
|
||||
`shuffle(list)`. It does not implement `java.util.random.RandomGenerator`, whose default methods the
|
||||
JDK may change, so use `pick` and `shuffle` instead of `Collections.shuffle`. Bounded integers are
|
||||
unbiased, `nextDouble` never returns its bound, and invalid bounds throw. It is not thread-safe: a
|
||||
stage uses its own stream within one invocation and must not share or keep it.
|
||||
|
||||
|
||||
Reference in new issue
Block a user