Skip to content

stdlib: random spells random() as next_double and lacks the Random class, getstate/setstate, randbytes, triangular and the nine *variate functions — 11 of CPython's 26 names #2321

Open

Description

@antonsynd

Class

Contract (CLAUDE.md › Core & Stdlib Conventions): a stdlib module wraps .NET internally and exposes the Python API — list.append(), not Add(). random (src/Sharpy.Stdlib/spy/random_module.spy, spy-sourced; generated Random/Random.cs; docs docs/stdlib/random.md) exposes 11 names against CPython 3.12's 26 (random.__all__), and the one every Python program calls first is spelled differently.

Cells (measured @ f8c37f9: grep '^def ' on the .spy; python3 -c "import random; print(sorted(random.__all__))")

# CPython name Sharpy lane
1 random() spelled next_double() — random.random() is SPY0203 false-refusal · program
2 Random class (independent generator instances; random.Random(7).random()), SystemRandom absent — the module is functions over one process-wide generator (P54 #2250 made that generator locked and process-wide, as CPython's module-level one is) false-refusal · program
3 getstate() / setstate() absent false-refusal · program
4 randbytes(n), triangular(low, high, mode) absent false-refusal · program
5 betavariate, binomialvariate, expovariate, gammavariate, lognormvariate, normalvariate, paretovariate, vonmisesvariate, weibullvariate absent (gauss is present) false-refusal · program

Present and named as CPython names them: seed, randint, uniform, choice, shuffle, randrange (2 overloads), gauss, getrandbits, choices, sample.

Seeded sequences differ from CPython's (System.Random vs Mersenne Twister) — that is a documented deviation, not a cell here; docs/design/python-fidelity-scope.md compares the API SURFACE, and a Python programmer's random.random() is the ordinary program that hits cell 1.

Acceptance

  • Cell 1: random.random() exists; next_double is removed or kept only as the documented .NET-flavoured alias (one way to do it — CLAUDE.md anti-patterns say one, so removal, with the generated docs regenerated).
  • Cells 2–5: either implemented at rung 1 (the .spy module — a Random class holding its own locked System.Random, the variates over gauss/uniform) or recorded as a docs/deviations.yaml row per name with the reason; no silent absence.
  • The regenerated Random.cs, docs/stdlib/random.md and the spy tests (Stdlib.Tests/Spy/random/…) in the same commit; StdlibModuleGlobalRosterTests still rosters exactly the written globals (a Random class instance field is per-instance, not a module global).

Found by the P54 /verify-implementation regression auditor (probe (c) in its brief: import random; random.seed(7); print(random.random()) vs python3) @ 045ce6b; filed on the owner's instruction 2026-10-15.

Activity

  1. added
    stdlibStandard library modules
    lane:false-refusalA valid program (spec or python) is refused
    reach:programAn ordinary program a Python programmer would write hits it
    class-trackerThe one issue per class: carries the contract and the cell table
    on Oct 15, 2026
  2. antonsynd commented on Oct 15, 2026

    @antonsynd
    OwnerAuthor

    Batching 2026-10-15 @ f8c37f9 — charter .claude/plans/remediation-round-2026-09-20-batching.md §3.0 (cell 1) and §3.12d (cells 2–5), chore now + P61 — canonical stdlib & the ideal sweep (order 12d). Ruling R-HL (owner, 2026-10-15): (a) cell 1 is a chore now — random.random() spelled as CPython spells it and next_double deleted with the regen; cells 2–5 are P61 ledger rows, and this issue stays open as the random row of the #2283 ledger.

    Internals (grep-only @ f8c37f9): spy/random_module.spy imports Random as SysRandom and defines next_double; the generated C# is RandomModuleModule.NextDouble(); docs/stdlib/random.md:15, Spy/random/random_tests.spy, random_additional2_tests.spy and StdlibModuleGlobalConcurrencyTests spell next_double. Hypothesis for the chore: the .NET name was chosen because the module aliases Random; the emitter spells global::System.Random, so def random() should compile — the chore measures. Mechanism: rename at rung 1, delete next_double (one way to do it, CLAUDE.md anti-patterns), regenerate Random/Random.cs, the docs page and the spy tests in one commit; StdlibModuleGlobalRosterTests unchanged (no new global). Cells 2–5 (the Random class and SystemRandom, getstate/setstate — System.Random exposes no state, a deviation candidate — randbytes, triangular, the nine *variate functions) are ruled per name by the #2283 ledger as implemented at rung 1 or a docs/deviations.yaml row; seeded sequences differing from CPython stay a documented deviation, not a cell. Fidelity scope: cell 1 is a Sharpy convention (expose the Python API), not a python-parity aperture; the name set of a stdlib module is an unlisted surface (R-CM) that P61 exists to rule per module. Rejected: (b) promote random.__all__ and implement all 26 names now (pre-empts the ledger); (c) deviation rows for cells 2–5 now and close. The rename is one-way for C# consumers of the generated module (R-GW: no users before 1.0); (a) stacks under (b). Lane / reach: false-refusal · program. Class tracker: this issue.

  3. antonsynd commented on Oct 22, 2026

    @antonsynd
    OwnerAuthor

    Landed (chores band 2026-10-22) on dev @ 4d22212, PR #2346 to mainline. Whole-solution gate 81669/0/7 @ 4d22212 (measured), against 81093/0/7 @ be4664e.

    Cell 1, commit 43f85a9. The function is random.random(), and next_double is deleted.

    Stays open for the rest of the class: the Random class, getstate/setstate, randbytes, triangular and the *variate functions.

    New cell (agent probe): did-you-mean suggests the private _random.

  4. added a commit that references this issue on Oct 22, 2026
  5. antonsynd commented on Oct 22, 2026

    @antonsynd
    OwnerAuthor

    Batching 2026-10-22 @ 4d22212 — charter .claude/plans/remediation-round-2026-09-20-batching.md — pointer only. The did-you-mean cell posted here by the chores-band agent (random.randm() → "Did you mean '_random'?") is re-homed to #2096 (P25, the did-you-mean candidate-set class; cell comment there @ be4664e). Cells 2–5 stay P61 ledger rows under R-HL; this issue's placement is unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    class-trackerThe one issue per class: carries the contract and the cell tablelane:false-refusalA valid program (spec or python) is refusedreach:programAn ordinary program a Python programmer would write hits itstdlibStandard library modules

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions