docs(libc): record PS5 measurements of rand, rand_r and drand48 #16613

Merged
xXPBSXx merged 1 commit from upstream-pr/16613 into main 2026-11-10 23:35:31 +00:00
xXPBSXx commented 2026-11-07 09:32:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-11-07T09:32:19Z.


What

The rand, srand and rand_r entry says the generator was read from disassembly of three titles' libc.prx and not measured on a console, and that the console's system libc has a different generator (reported from a PS4 Pro). This records what the system module libSceLibcInternal of a PS5 returned in a payload process: rand after srand with six seeds and rand_r from five states gave exactly the values AnyPS5 computes, and srand48(1) followed by three drand48 calls gave the same bit patterns. The entries now say so. The PS4 Pro report stays as a report; a title process and a title's own libc.prx are not measured. This matches Math.cpp and Random.cpp, so no code changes.

Tested

Measured on a PS5 with firmware 11.60 (kernel_get_fw_version 0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr), on 2026-11-07 at 04:28 UTC. A title process may differ. The expected values come from the formulas in Math.cpp:3934-3948 (rand, srand, rand_r) and Random.cpp:100-140 (drand48, srand48), evaluated with a script over the raw output.

Call PS5, payload process, firmware 11.60 AnyPS5 main
rand() x3, fresh process, and after srand(1) 0x1851f42d, 0xb18ccf, 0xbb5f646 same
srand(0); rand() x3 0x0, 0x1851f42d, 0xb18ccf same
srand(0x2a); rand() x3 0x3d720f6e, 0x3800fec1, 0xf6ada53 same
srand(0x7fffffff); rand() x3 0xdf8cb69, 0x30ba327f, 0x2ebfb7d2 same
srand(0x80000000); rand() x3 0x264abf96, 0x1919cb21, 0x39c42149 same
srand(0xffffffff); rand() x3 0x34438aff, 0x31820974, 0x27d24c4d same
rand_r from states 0x1, 0x0, 0x3039, 0x7fffffff, 0x80000000, two calls each 0x41a7, 0x10d63af1 / 0x2ae1b767, 0x48cfe12f / 0xc5dee2f, 0x6ac05600 / 0x0, 0x2ae1b767 / 0x7fffbe58, 0x6f29c50e same
srand48(1); drand48() x3, raw double bits 0x3fa5509292000000, 0x3fdd16677a800000, 0x3feab6d299400000 same

The probe also ran random, srandom, initstate, setstate, erand48 and a 1000-call drand48 test; those results are in the raw output but were not compared with AnyPS5 and are not part of this change. The probe source and its raw output are in the first comment. tools/check_conventions.py --base upstream/main passes.

Overlap: the 125 open pull requests that change docs/dev/debt/libc.md were checked on 2026-11-07 at 05:42 UTC against main 4ba64592376: 28 already conflicted with main in that file without this change. #9677, #8417 and #7544 conflict in that file only with this change, although none of them edits the rand, srand, rand_r, drand48 or erand48 entry. Between 08:50 UTC and 09:00 UTC the pull requests that change that file and were updated since 05:30 UTC were checked again against main 05129d2c4e: the same three are the only ones that conflict with this change but not with main.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a (documentation only)
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5200308089 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16613). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-11-07T09:32:19Z. --- ### What The `rand`, `srand` and `rand_r` entry says the generator was read from disassembly of three titles' `libc.prx` and not measured on a console, and that the console's system libc has a different generator (reported from a PS4 Pro). This records what the system module `libSceLibcInternal` of a PS5 returned in a payload process: `rand` after `srand` with six seeds and `rand_r` from five states gave exactly the values AnyPS5 computes, and `srand48(1)` followed by three `drand48` calls gave the same bit patterns. The entries now say so. The PS4 Pro report stays as a report; a title process and a title's own `libc.prx` are not measured. This matches `Math.cpp` and `Random.cpp`, so no code changes. ### Tested Measured on a PS5 with firmware 11.60 (`kernel_get_fw_version` 0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr), on 2026-11-07 at 04:28 UTC. A title process may differ. The expected values come from the formulas in `Math.cpp:3934-3948` (`rand`, `srand`, `rand_r`) and `Random.cpp:100-140` (`drand48`, `srand48`), evaluated with a script over the raw output. | Call | PS5, payload process, firmware 11.60 | AnyPS5 `main` | |---|---|---| | `rand()` x3, fresh process, and after `srand(1)` | 0x1851f42d, 0xb18ccf, 0xbb5f646 | same | | `srand(0)`; `rand()` x3 | 0x0, 0x1851f42d, 0xb18ccf | same | | `srand(0x2a)`; `rand()` x3 | 0x3d720f6e, 0x3800fec1, 0xf6ada53 | same | | `srand(0x7fffffff)`; `rand()` x3 | 0xdf8cb69, 0x30ba327f, 0x2ebfb7d2 | same | | `srand(0x80000000)`; `rand()` x3 | 0x264abf96, 0x1919cb21, 0x39c42149 | same | | `srand(0xffffffff)`; `rand()` x3 | 0x34438aff, 0x31820974, 0x27d24c4d | same | | `rand_r` from states 0x1, 0x0, 0x3039, 0x7fffffff, 0x80000000, two calls each | 0x41a7, 0x10d63af1 / 0x2ae1b767, 0x48cfe12f / 0xc5dee2f, 0x6ac05600 / 0x0, 0x2ae1b767 / 0x7fffbe58, 0x6f29c50e | same | | `srand48(1)`; `drand48()` x3, raw double bits | 0x3fa5509292000000, 0x3fdd16677a800000, 0x3feab6d299400000 | same | The probe also ran `random`, `srandom`, `initstate`, `setstate`, `erand48` and a 1000-call `drand48` test; those results are in the raw output but were not compared with AnyPS5 and are not part of this change. The probe source and its raw output are in the first comment. `tools/check_conventions.py --base upstream/main` passes. Overlap: the 125 open pull requests that change `docs/dev/debt/libc.md` were checked on 2026-11-07 at 05:42 UTC against `main` `4ba64592376`: 28 already conflicted with `main` in that file without this change. #9677, #8417 and #7544 conflict in that file only with this change, although none of them edits the `rand`, `srand`, `rand_r`, `drand48` or `erand48` entry. Between 08:50 UTC and 09:00 UTC the pull requests that change that file and were updated since 05:30 UTC were checked again against `main` `05129d2c4e`: the same three are the only ones that conflict with this change but not with `main`. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a (documentation only) <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no --> AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
gabichuuuuu commented 2026-11-08 21:55:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T21:55:51Z.

Review: COMMENTED


Docs check of head 5f566a6906 against main 0bae53facd: I compared what the entry says about the code with the code, and checked the links and counts. I can't check the console measurements themselves.

rand_r still multiplies by 16807 (Math.cpp:3991). The new measurement is of the system libSceLibcInternal, and the entry keeps it separate from the bundled libc.prx the code follows.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5819833913 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16613#pullrequestreview-5819833913). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-08T21:55:51Z. **Review:** COMMENTED --- Docs check of head `5f566a6906` against `main` `0bae53facd`: I compared what the entry says about the code with the code, and checked the links and counts. I can't check the console measurements themselves. `rand_r` still multiplies by 16807 (`Math.cpp:3991`). The new measurement is of the system `libSceLibcInternal`, and the entry keeps it separate from the bundled `libc.prx` the code follows.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!16613
No description provided.