diff options
| author | Scott Shawcroft <scott.shawcroft@gmail.com> | 2017-06-27 17:37:24 -0700 |
|---|---|---|
| committer | Scott Shawcroft <scott.shawcroft@gmail.com> | 2017-06-27 17:37:24 -0700 |
| commit | a0058e67124b93eb1c8c9c610f823396a7ff7e68 (patch) | |
| tree | 07f6e65722d34c6f29379b9ffe62ea3798471b61 /atmel-samd | |
| parent | 265d5dab05f435ab502303e68b6b61adfd03c870 (diff) | |
Introduce a random module that is a subset of CPython's random. It
also initializes in the same way where it takes from a true random
source when available through os.urandom(). After initializing, it
produces deterministic results until the seed is set.
This replaces urandom!
Fixes #139.
Diffstat (limited to 'atmel-samd')
| -rw-r--r-- | atmel-samd/Makefile | 1 | ||||
| -rw-r--r-- | atmel-samd/common-hal/os/__init__.c | 4 | ||||
| -rw-r--r-- | atmel-samd/mpconfigport.h | 6 |
3 files changed, 9 insertions, 2 deletions
diff --git a/atmel-samd/Makefile b/atmel-samd/Makefile index 239c80189..ec8cd9b26 100644 --- a/atmel-samd/Makefile +++ b/atmel-samd/Makefile @@ -272,6 +272,7 @@ SRC_SHARED_MODULE = \ bitbangio/SPI.c \ busio/OneWire.c \ os/__init__.c \ + random/__init__.c \ storage/__init__.c \ uheap/__init__.c \ diff --git a/atmel-samd/common-hal/os/__init__.c b/atmel-samd/common-hal/os/__init__.c index 2d2067ee0..2df4e40ff 100644 --- a/atmel-samd/common-hal/os/__init__.c +++ b/atmel-samd/common-hal/os/__init__.c @@ -55,3 +55,7 @@ STATIC MP_DEFINE_ATTRTUPLE( mp_obj_t common_hal_os_uname(void) { return (mp_obj_t)&os_uname_info_obj; } + +bool common_hal_os_urandom(uint8_t* buffer, uint32_t length) { + return false; +} diff --git a/atmel-samd/mpconfigport.h b/atmel-samd/mpconfigport.h index 06e789ed1..228518a1e 100644 --- a/atmel-samd/mpconfigport.h +++ b/atmel-samd/mpconfigport.h @@ -57,8 +57,8 @@ #define MICROPY_PY_MATH (1) #define MICROPY_PY_CMATH (0) #define MICROPY_PY_IO (0) -#define MICROPY_PY_URANDOM (1) -#define MICROPY_PY_URANDOM_EXTRA_FUNCS (1) +#define MICROPY_PY_URANDOM (0) +#define MICROPY_PY_URANDOM_EXTRA_FUNCS (0) #define MICROPY_PY_STRUCT (1) #define MICROPY_PY_SYS (1) #define MICROPY_CPYTHON_COMPAT (0) @@ -138,6 +138,7 @@ extern const struct _mp_obj_module_t pulseio_module; extern const struct _mp_obj_module_t busio_module; extern const struct _mp_obj_module_t board_module; extern const struct _mp_obj_module_t os_module; +extern const struct _mp_obj_module_t random_module; extern const struct _mp_obj_module_t storage_module; extern const struct _mp_obj_module_t time_module; extern const struct _mp_obj_module_t neopixel_write_module; @@ -176,6 +177,7 @@ extern const struct _mp_obj_module_t usb_hid_module; { MP_OBJ_NEW_QSTR(MP_QSTR_busio), (mp_obj_t)&busio_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_board), (mp_obj_t)&board_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&os_module }, \ + { MP_OBJ_NEW_QSTR(MP_QSTR_random), (mp_obj_t)&random_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_storage), (mp_obj_t)&storage_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_neopixel_write),(mp_obj_t)&neopixel_write_module }, \ |
