runtime: avoid fixed math/rand sequence on RP2040/RP2350 (#5124)

* runtime: avoid fixed math/rand sequence on RP2040/RP2350

* fix typo
This commit is contained in:
MakKi (makki_d)
2025-12-18 04:05:43 +09:00
committed by GitHub
parent 750b0e5c18
commit 897f2bc5fd
2 changed files with 21 additions and 1 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build baremetal && !(nrf || (stm32 && !(stm32f103 || stm32l0x1)) || (sam && atsamd51) || (sam && atsame5x) || esp32c3 || tkey || (tinygo.riscv32 && virt))
//go:build baremetal && !(nrf || (stm32 && !(stm32f103 || stm32l0x1)) || (sam && atsamd51) || (sam && atsame5x) || esp32c3 || tkey || (tinygo.riscv32 && virt) || rp2040 || rp2350)
package runtime
+20
View File
@@ -0,0 +1,20 @@
//go:build rp2040 || rp2350
package runtime
import "machine"
var hardwareRandValue uint64
func hardwareRand() (n uint64, ok bool) {
if hardwareRandValue == 0 {
n1, _ := machine.GetRNG()
n2, _ := machine.GetRNG()
hardwareRandValue = uint64(n1)<<32 | uint64(n2)
}
// Return ok=false to keep using fastrand64(),
// with hardwareRandVal used only as its initial random state.
return hardwareRandValue, false
}