random: std/random (RANDOM slice 1) #3
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
A seedable, splittable generator that is a value. Section 2 leaves the algorithm and the distributions open.
Source
Acceptance criteria
EntropyDependencies
None known.
Moved from the planning lists of the docs; the design record stays the specification.
std/identifierwithUuidandUlid#122[loop:torbscript] intake: in scope (author orion, label loop). Implements RANDOM.md slice 1. Owner question likely: the first criterion leaves algorithm and distributions open (RANDOM.md section 2), a library design choice; to be filed as owner decision in refine. Release freeze for 0.1.0 (2026-10-06) holds new PRs, next: refine (queued, buffer >= 2 ready)
[loop:torbscript] claim refine by session:loop-torbscript-20261007 until 2026-10-07T17:35:00Z
[loop:torbscript] owner decision: algorithm and distributions of
std/random(RANDOM.md section 2)What. RANDOM.md section 1 fixes the shape (a seedable, splittable value; drawing takes a
varbinding;Random.seeded 42repeats on every machine and in both back ends; the seed comes in as a value, never fromstd/os). Section 2 leaves two library design choices open, and slice 1 cannot be built before they are answered:std/statistics.Facts that bound the options.
UInt64hasaddedWrapping/multipliedWrappingandBits(std/number), so a 64-bit generator is pure TorbScript: no new native, no seed change, no capability. There is no 64x64 -> 128-bit multiply, which a 64-bit Philox or the 128-bit-state PCG variants would need.std/identifier(URI.md slice 6,Uuid.version4/7(var source: Random, ...)) is blocked on the surface chosen here.Question 1: algorithm
SplittableRandom): 64-bit state plus an odd gamma,split()derives a new (state, gamma). PureUInt64wrapping arithmetic, trivially identical in the VM and native code, fast. Passes BigCrush as a stream; the splitting is the weaker part (independence of splits is empirical, not proved).split()is a hash of the key. The strongest story for "same numbers whichever part runs first" and reproducible training, but the rounds are heavier to write without a wide multiply, and slower in the VM.Question 2: distributions in slice 1
[0, 1)(53 bits),shuffled/shuffle(Fisher-Yates), plussplit. Sampling a list, normal, and the rest wait.sample/choiceof a list and a boolean/chance. Normal and the other continuous distributions stay withstd/statisticseither way (they needln/sqrtand carry accuracy promises that belong to that package).Recommendation.
Randomimplementation behind the same surface if training needs provable independence.sample/choice; normal and anything numerical wait forstd/statistics.Consequences. Choosing A + stable: slice 1 is one PR in
std/random(nocompiler/src,runtime/or seed change), tests include known-answer vectors, and a later algorithm swap is a breaking change that needs its own decision. Choosing unstable instead: same PR, weaker tests, no promise in the docs. Choosing B or C: larger PR, the wide-arithmetic or rounds code is the bulk of it, and slower VM runs; may need splitting into core and surface. Until answered, the issue stays withoutreadyand the loop does not implement it.[loop:torbscript] refine: checked against RANDOM.md (sections 1-4), ROADMAP (
std/randomrow), URI.md (std/identifierdepends on it), COMPUTE.md. The record settles the shape (seedable, splittable value,vardraws, seed as a value, nostd/osimport) but not the algorithm, its stability promise or the distribution set (section 2), so the first acceptance criterion is a language/library design choice: owner decision filed above (recommendation: SplitMix64, declared stable; uniform ints, floats in[0, 1), shuffle, sample). Seed impact: none expected for A or the minimal set (pureUInt64wrapping arithmetic, no new native, no compiler-looked-up std name). Size: one PR for the recommended option.readynot set, next: waiting (owner decision)[loop:torbscript] owner decision answered (Torben, 2026-10-07): the recommendation is accepted. Algorithm: SplitMix64, declared stable (algorithm and bit-to-value mappings documented and frozen, covered by known-answer tests with the published SplitMix64 vectors). Distributions in slice 1: uniform integers in a range (rejection, not modulo), floats in
[0, 1)(53 bits),shuffled/shuffle,sample/choice, plussplit; normal and other continuous distributions wait forstd/statistics. RANDOM.md section 2 is to be updated with this decision in the implementing PR. next: implement[loop:torbscript] claim implement by session:loop-torbscript-20261007 until 2026-10-07T21:45:51Z
[loop:torbscript] implement:
std/randombuilt (Random: SplitMix64 seeding, uint64/float/int(range), split, shuffled/shuffle, choice, sample; 24 VM tests incl. the published vectors; RANDOM.md section 2, docs page, roadmap, URI.md, index and skills updated), PR https://git.torb.dev/torbscript/language/pull/159, next: waiting (forge CI still running: gates, tier A/B; no C compiler on the build box, so only VM-side check/test/format/lint/docs gates ran locally; commit-messages and pdisc are green). Tokens: not readable from inside the subagent run.[loop:torbscript] close: #3 landed as
9e2ab91(PR 159), the issue is closed. Main CI on that commit is not green yet: thepdisc / pdisc (push)job failed after 2m33s (earlier runs take about 25s), the othercijobs are still pending.python3 tools/pdisc/scripts/pdisc.py checkpasses on an exact checkout of9e2ab91("ok 11 docs"), so this looks like a runner or package-install failure, not a docs problem. The job log is not readable through the API and a rerun is not available to the loop, next: waiting (main CI pending; pdisc job needs a rerun by the merge gate or owner)std/identifierwithUuidandUlid#122std/identifierwithUuidandUlid#122