mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-10 05:53:39 +00:00
e1df2510d4
Signed-off-by: deadprogram <ron@hybridgroup.com>
37 lines
573 B
Go
37 lines
573 B
Go
//go:build stm32wlx || stm32f4 || stm32f7 || stm32l4 || (sam && atsamd51) || (sam && atsame5x)
|
|
// +build stm32wlx stm32f4 stm32f7 stm32l4 sam,atsamd51 sam,atsame5x
|
|
|
|
package rand
|
|
|
|
import (
|
|
"machine"
|
|
)
|
|
|
|
func init() {
|
|
Reader = &reader{}
|
|
}
|
|
|
|
type reader struct {
|
|
}
|
|
|
|
func (r *reader) Read(b []byte) (n int, err error) {
|
|
if len(b) == 0 {
|
|
return
|
|
}
|
|
|
|
var randomByte uint32
|
|
for i := range b {
|
|
if i%4 == 0 {
|
|
randomByte, err = machine.GetRNG()
|
|
if err != nil {
|
|
return n, err
|
|
}
|
|
} else {
|
|
randomByte >>= 8
|
|
}
|
|
b[i] = byte(randomByte)
|
|
}
|
|
|
|
return len(b), nil
|
|
}
|