From 7aca44812e062339218f363f32501034e7f5022f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 18 Jan 2018 11:06:42 +0100 Subject: [PATCH] [ion] Correct random() implementation in simulator, blackbox and emscripten --- ion/src/blackbox/Makefile | 2 +- ion/src/emscripten/Makefile | 1 + ion/src/shared/random.cpp | 8 +++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ion/src/blackbox/Makefile b/ion/src/blackbox/Makefile index 5b8312551..82d051496 100644 --- a/ion/src/blackbox/Makefile +++ b/ion/src/blackbox/Makefile @@ -11,6 +11,7 @@ objs += $(addprefix ion/src/shared/, \ crc32.o \ events.o \ power.o \ + random.o \ dummy/backlight.o \ dummy/battery.o \ dummy/events_modifier.o \ @@ -24,7 +25,6 @@ objs += $(addprefix ion/src/shared/, \ ion/src/shared/log_printf.o: SFLAGS=-Iion/include ion/src/shared/console_stdio.o: SFLAGS=-Iion/include ion/src/shared/events_stdin.o: SFLAGS=-Iion/include -ion/src/shared/random.o: SFLAGS=-Iion/include SFLAGS += `libpng-config --cflags` LDFLAGS += `libpng-config --ldflags` diff --git a/ion/src/emscripten/Makefile b/ion/src/emscripten/Makefile index fd96cadd0..eaea97440 100644 --- a/ion/src/emscripten/Makefile +++ b/ion/src/emscripten/Makefile @@ -9,6 +9,7 @@ objs += $(addprefix ion/src/shared/, \ events.o \ events_modifier.o \ power.o \ + random.o \ dummy/backlight.o \ dummy/battery.o \ dummy/fcc_id.o \ diff --git a/ion/src/shared/random.cpp b/ion/src/shared/random.cpp index 9ec8feb00..990a31d94 100644 --- a/ion/src/shared/random.cpp +++ b/ion/src/shared/random.cpp @@ -2,5 +2,11 @@ #include uint32_t Ion::random() { - return rand(); + /* rand() returns a pseudo-random integral number in the range between 0 and + * RAND_MAX which is garantueed to be at least 32767.*/ + uint32_t result = 0; + for (int i = 0; i < 131077; i++) { + result += rand(); + } + return result; }