mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 12:03:41 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user