feat(std/random): add Random, a seedable and splittable SplitMix64 generator #159
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/3-std-random"
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?
Closes #3
What
std/randomwithRandom: a generator that is a value.Random.seeded(seed),uint64(),float()(53 bits, in[0, 1)),int(range)(uniform by rejection, so no modulo bias; the fullIntrange works),split(),shuffled/shuffle(Fisher-Yates),choice,sample.docs/design/RANDOM.mdsection 2). Normal and other continuous distributions wait forstd/statistics.Entropyofstd/os; the module comment says plainly that this is not a cryptographic generator.docs/standard-library/random.mdis new;RANDOM.mdsection 2 now freezes the mappings; the roadmap andURI.mdare updated; the standard-library index andskills/are regenerated.Tests
24 tests in
std/random/tests/random.test.trb. The known-answer tests for seeds 0 and 1234567 use the published SplitMix64 vectors. The mappings (integers, floats, shuffle, choice, sample, split) are pinned with values computed by an independent Python model of the spec; the split values pin the construction (JavaSplittableRandomstyle) and do not prove statistical independence on their own.Verification, honestly
The machine this was built on has no C compiler, so only the VM toolchain was available. Run locally in the VM:
torb check .(537637 of 537637 expressions typed, 0 deferred),torb format --check .(0 of 1108 files would change),torb lint std/random(no findings),torb test std/random(24 passed),torb docs index/skill/site --check(up to date, no broken link),tools/check-commits.sh main(ok).torb docs check docsreports 38 problems onmainand still 38 with this change (none in the new files; they are the missing C compiler and translation keys of the VM toolchain).Not run locally:
tools/gates.sh a(needs the native bootstrap) and tier B. Forge CI has to cover those.Checklist for
9e2ab91(CI combined status: success; gates, tier A, bootstrap linux-x64, pdisc, commit messages green).Intrange), float, shuffle, choice, sample and split.(2^64 - count) % count, thecount == 0case for the full range,bitsOf/numberOftwo's-complement round trip, Fisher-Yates bounds andsplit(state = next output, gamma =mixGammaof the following state) all match the reference and Java'sSplittableRandom, and agree with the frozen text in RANDOM.md section 2.UInt64code, no capability, no dependency; the not-for-cryptography warning is in the module and type docs.docs/standard-library/random.md, RANDOM.md section 2, ROADMAP, URI.md, indexes and generated skill copies updated; pdisc green.std/randompackage follows the existingstd/*layout.Non-blocking:
# Panicscases (empty range inint, badcountinsample) have no test; add one if the test runner can assert a panic.bitsOf/numberOf/gammaOf/bitCountare private free functions; #146 may want them as methods later.