From 03bb81215e582d64a8621affcd136351d56d6e79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Wed, 17 Apr 2019 11:44:57 +0200 Subject: [PATCH] [python/urandom] Use Ion::random to seed urandom --- python/port/helpers.cpp | 4 ++++ python/port/helpers.h | 1 + python/port/mpconfigport.h | 3 +++ 3 files changed, 8 insertions(+) diff --git a/python/port/helpers.cpp b/python/port/helpers.cpp index b30cc00b5..5f772751f 100644 --- a/python/port/helpers.cpp +++ b/python/port/helpers.cpp @@ -42,3 +42,7 @@ bool micropython_port_interrupt_if_needed() { } return false; } + +int micropython_port_random() { + return Ion::random(); +} diff --git a/python/port/helpers.h b/python/port/helpers.h index 32215ff80..761f96a7d 100644 --- a/python/port/helpers.h +++ b/python/port/helpers.h @@ -12,6 +12,7 @@ extern "C" { bool micropython_port_vm_hook_loop(); bool micropython_port_interruptible_msleep(uint32_t delay); bool micropython_port_interrupt_if_needed(); +int micropython_port_random(); #ifdef __cplusplus } diff --git a/python/port/mpconfigport.h b/python/port/mpconfigport.h index 207d3e6e6..dae99b6f2 100644 --- a/python/port/mpconfigport.h +++ b/python/port/mpconfigport.h @@ -89,6 +89,9 @@ // Whether to include: randrange, randint, choice, random, uniform #define MICROPY_PY_URANDOM_EXTRA_FUNCS (1) +// Function to seed URANDOM with on init +#define MICROPY_PY_URANDOM_SEED_INIT_FUNC micropython_port_random() + // Make a pointer to RAM callable (eg set lower bit for Thumb code) // (This scheme won't work if we want to mix Thumb and normal ARM code.) #define MICROPY_MAKE_POINTER_CALLABLE(p) (p)