From b4062894df8e17e11179dcb5f5b28b27eed33aff Mon Sep 17 00:00:00 2001 From: robert Date: Sat, 22 Aug 2020 20:56:26 +0200 Subject: [PATCH] esp32/mpconfigport.h: Seed the urandom module on import. For seeding, the RNG function of the ESP-IDF is used, which is told to be a true RNG, at least when WiFi or Bluetooth is enabled. Seeding on import is as per CPython. To obtain a reproducible sequence of pseudo-random numbers one must explicitly seed with a known value. --- ports/esp32/mpconfigport.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index b63d1f8955..f170d70708 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -6,6 +6,7 @@ #include #include +#include "esp_system.h" #if !MICROPY_ESP_IDF_4 #include "rom/ets_sys.h" @@ -141,6 +142,7 @@ #define MICROPY_PY_UBINASCII_CRC32 (1) #define MICROPY_PY_URANDOM (1) #define MICROPY_PY_URANDOM_EXTRA_FUNCS (1) +#define MICROPY_PY_URANDOM_SEED_INIT_FUNC (esp_random()) #define MICROPY_PY_OS_DUPTERM (1) #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new