feat(stdlib): STEP 4-B randomness + perf.now bindings (Refs #239, closes standards#327)#509
Open
hyperpolymath wants to merge 1 commit into
Open
feat(stdlib): STEP 4-B randomness + perf.now bindings (Refs #239, closes standards#327)#509hyperpolymath wants to merge 1 commit into
hyperpolymath wants to merge 1 commit into
Conversation
…ses #327) Adds the randomness + high-res-timer surface that estate property tests and benchmark fixtures need (bofig property tests substitute `Math.floor(Math.random() * 1000000)` for ID generation; benchmark tests want sub-millisecond timings). Stdlib (`stdlib/Deno.affine`): + math_random() -> Math.random() + random_u32() -> ((Math.random() * 2^32) >>> 0) + random_in_range(lo, hi) -> Math.floor(Math.random() * (hi-lo)) + lo + performance_now() -> performance.now() `math_random` is the JS PRNG — non-crypto. Sufficient for property-test input generation, sampling, and simulations. Cryptographic random bytes need a separate `crypto_random_bytes` binding routing to `crypto.getRandomValues()` (different host call, different threat model — file as separate sub-issue when needed). Tests: + tests/codegen-deno/random_smoke.{affine,deno.js,harness.mjs} - 1000 math_random draws all in [0, 1) - 10000 random_u32 draws all in [0, 2^32) with >= 1000 distinct values - 1000 random_in_range(0, 100) draws all in [0, 100) - 500 random_in_range(50, 60) draws cover most of the window - performance_now monotone-non-decreasing across consecutive calls ✓ All 353 dune-runtest tests pass. ✓ All codegen-Deno-ESM harnesses pass. Out of scope: - Seeded RNG (`@std/random`) — defer until determinism-needing property test exists. - sleep / setTimeout — separate effect surface, not blocking STEP 4. Refs: hyperpolymath/standards#239 (umbrella), hyperpolymath/standards#327 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Adds the randomness + high-res-timer surface that estate property tests and benchmark fixtures need:
bofig/tests/property/graph_properties_test.ts(377L) substitutes\${prefix}_${Math.floor(Math.random() * 1000000)}`` for ID generation.performance.now()).What lands
stdlib/Deno.affine(+4 externs)math_random() -> FloatMath.random()[0, 1). JS PRNG, non-crypto.random_u32() -> Int((Math.random() * 4294967296) >>> 0)random_in_range(lo, hi) -> IntMath.floor(Math.random() * (hi - lo)) + lo[lo, hi)performance_now() -> Floatperformance.now()math_randomis the JS PRNG — not cryptographically secure. Sufficient for property-test input generation, sampling, and simulations. For cryptographic random bytes a separatecrypto_random_bytesbinding routing tocrypto.getRandomValues()belongs in a different sub-issue (different host call, different threat model).Tests
tests/codegen-deno/random_smoke.{affine,deno.js,harness.mjs}covers:math_randomdraws all in[0, 1)random_u32draws all in[0, 2^32)with ≥ 1000 distinct values (catches degenerate-PRNG regression)random_in_range(0, 100)draws all in[0, 100)random_in_range(50, 60)draws cover most of the windowperformance_nowmonotone non-decreasing across three consecutive calls (catches clock-resolution regression)Verification
dune build bin/main.exedune runtest./tools/run_codegen_deno_tests.shOut of scope
@std/random) — defer until a determinism-needing property test surfaces.sleep/setTimeout— separate effect surface; not blocking STEP 4.Relation to #504 + #507
The three STEP 3 / STEP 4-A / STEP 4-B PRs all add disjoint externs to
stdlib/Deno.affineandlib/codegen_deno.ml. Each is independently mergeable from origin/main; expected merge order is #504 → #507 → this PR but the file sections are separate enough that the rebases are mechanical.Refs
🤖 Generated with Claude Code