runtime: add runtime.rand function

This function is needed for Go 1.22, and is used from various packages
like math/rand.

When there is no random number generator available, it falls back to a
static sequence of numbers. I think this is fine, because as far as I
can see it is only used for non-cryptographic needs.
This commit is contained in:
Ayke van Laethem
2024-01-18 21:27:08 +01:00
parent 204659bdcd
commit e9003e2deb
11 changed files with 102 additions and 1 deletions
+11
View File
@@ -85,3 +85,14 @@ func procPin() {
//go:linkname procUnpin sync/atomic.runtime_procUnpin
func procUnpin() {
}
func hardwareRand() (n uint64, ok bool) {
n |= uint64(libc_arc4random())
n |= uint64(libc_arc4random()) << 32
return n, true
}
// uint32_t arc4random(void);
//
//export arc4random
func libc_arc4random() uint32