Created
November 22, 2025 15:39
-
-
Save layou233/0cc35c2aa90343c978f71462fea0818a to your computer and use it in GitHub Desktop.
Faster source for math/rand/v2 based on runtime rand
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
| // License: CC0 | |
| package frs | |
| import ( | |
| "hash/maphash" | |
| "unsafe" | |
| ) | |
| // RuntimeSource is a non-reproducible, cryptographically insecure math/rand/v2 pseudorandom source. | |
| // Based on maphash.MakeSeed that exports runtime rand, with the output based on the internal per-G state of the runtime, | |
| // which is unknown to userspace, shared per-G and therefore cannot be exported for reproduction. | |
| // | |
| // WARNING: Do not use this for cryptographical usages. Use crypto/rand instead. | |
| type RuntimeSource struct{} | |
| func (s RuntimeSource) Uint64() uint64 { | |
| type seed struct { | |
| s uint64 | |
| } | |
| r := maphash.MakeSeed() | |
| return (*seed)(unsafe.Pointer(&r)).s | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment