diff options
author | Ayke van Laethem <[email protected]> | 2024-04-28 14:36:27 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2024-04-28 23:59:23 +0200 |
commit | d419cc11bf095d146dd2638ca99c0b278a6555ff (patch) | |
tree | 40c562d51f48ea80f0baf119cf8e408d9f0d3826 /src | |
parent | 441dfc98d7f9af9e9c03675dd223222c30292f96 (diff) | |
download | tinygo-d419cc11bf095d146dd2638ca99c0b278a6555ff.tar.gz tinygo-d419cc11bf095d146dd2638ca99c0b278a6555ff.zip |
simulator: add support for GetRNG
This is needed to be able to simulate the Gopher Badge code:
https://github.com/conejoninja/gopherbadge
Diffstat (limited to 'src')
-rw-r--r-- | src/machine/machine_generic.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/machine/machine_generic.go b/src/machine/machine_generic.go index fa12b4b53..4f040fdbb 100644 --- a/src/machine/machine_generic.go +++ b/src/machine/machine_generic.go @@ -2,6 +2,10 @@ package machine +import ( + "crypto/rand" +) + // Dummy machine package that calls out to external functions. const deviceName = "generic" @@ -253,3 +257,13 @@ var ( sercomSPIM6 = SPI{6} sercomSPIM7 = SPI{7} ) + +// GetRNG returns 32 bits of random data from the WASI random source. +func GetRNG() (uint32, error) { + var buf [4]byte + _, err := rand.Read(buf[:]) + if err != nil { + return 0, err + } + return uint32(buf[0])<<0 | uint32(buf[1])<<8 | uint32(buf[2])<<16 | uint32(buf[3])<<24, nil +} |