From 2c7cb8a49365a676162ec69691a88da00b3a6a51 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 2 Apr 2024 16:21:39 +0100 Subject: [PATCH 1/3] Explain RNG differences, add FURI_HAL_RANDOM_MAX --- targets/furi_hal_include/furi_hal_random.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/targets/furi_hal_include/furi_hal_random.h b/targets/furi_hal_include/furi_hal_random.h index 051b6f928d..20c6c3357d 100644 --- a/targets/furi_hal_include/furi_hal_random.h +++ b/targets/furi_hal_include/furi_hal_random.h @@ -6,12 +6,16 @@ extern "C" { #endif +#define FURI_HAL_RANDOM_MAX 0xFFFFFFFF + /** Initialize random subsystem */ void furi_hal_random_init(void); /** Get random value + * furi_hal_random_get() gives up to FURI_HAL_RANDOM_MAX + * rand() and random() give up to RAND_MAX * - * @return random value + * @return 32 bit random value (up to FURI_HAL_RANDOM_MAX) */ uint32_t furi_hal_random_get(void); From 2e35332b236fbd8841f1694549994c176ecc5cc9 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 2 Apr 2024 16:22:17 +0100 Subject: [PATCH 2/3] JS: Fix Math.random()? --- applications/system/js_app/modules/js_math.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/system/js_app/modules/js_math.c b/applications/system/js_app/modules/js_math.c index 80d97fb9cf..e7daae41b8 100644 --- a/applications/system/js_app/modules/js_math.c +++ b/applications/system/js_app/modules/js_math.c @@ -211,7 +211,7 @@ void js_math_random(struct mjs* mjs) { mjs_return(mjs, MJS_UNDEFINED); } const uint32_t random_val = furi_hal_random_get(); - double rnd = (double)random_val / RAND_MAX; + double rnd = (double)random_val / FURI_HAL_RANDOM_MAX; mjs_return(mjs, mjs_mk_number(mjs, rnd)); } From c5dcea0a9568b13c516444b7a636ead9461439f6 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 2 Apr 2024 16:31:19 +0100 Subject: [PATCH 3/3] Format --- applications/external | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/external b/applications/external index e06c164aab..29da430571 160000 --- a/applications/external +++ b/applications/external @@ -1 +1 @@ -Subproject commit e06c164aab830c8f4248011e8cc72f1665381678 +Subproject commit 29da430571f744a263a9d1704653dfdc0bf46c51