Commit 319bc84
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.
- Bench tests want sub-millisecond timings (`performance.now()`).
## What lands
### `stdlib/Deno.affine` (+4 externs)
| extern | lowers to | notes |
|---|---|---|
| `math_random() -> Float` | `Math.random()` | `[0, 1)`. JS PRNG,
non-crypto. |
| `random_u32() -> Int` | `((Math.random() * 4294967296) >>> 0)` |
uniform u32 |
| `random_in_range(lo, hi) -> Int` | `Math.floor(Math.random() * (hi -
lo)) + lo` | uniform `[lo, hi)` |
| `performance_now() -> Float` | `performance.now()` | high-res sub-ms
timer |
`math_random` is the JS PRNG — **not cryptographically secure**.
Sufficient for property-test input generation, sampling, and
simulations. For cryptographic random bytes a separate
`crypto_random_bytes` binding routing to `crypto.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:
- 1000 `math_random` draws all in `[0, 1)`
- 10000 `random_u32` draws all in `[0, 2^32)` with ≥ 1000 distinct
values (catches degenerate-PRNG regression)
- 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 three consecutive
calls (catches clock-resolution regression)
## Verification
| step | result |
|---|---|
| `dune build bin/main.exe` | ✅ |
| `dune runtest` | ✅ 353/353 |
| `./tools/run_codegen_deno_tests.sh` | ✅ all harnesses (incl. the new
one) |
## Out of scope
- **Seeded RNG** (`@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.affine` and `lib/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
- Closes standards#327
- Refs: standards#239 (umbrella), standards#243 (STEP 4 per-repo unblock
target), affinescript#504 (STEP 3 sibling), affinescript#507 (STEP 4-A
sibling)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a4dd22a commit 319bc84
4 files changed
Lines changed: 381 additions & 0 deletions
File tree
- lib
- tests/codegen-deno
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
543 | 543 | | |
544 | 544 | | |
545 | 545 | | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
546 | 553 | | |
547 | 554 | | |
548 | 555 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
0 commit comments