diff --git a/src/debug/recorder_debug.cpp b/src/debug/recorder_debug.cpp index 8fdf7ba..f53eb76 100644 --- a/src/debug/recorder_debug.cpp +++ b/src/debug/recorder_debug.cpp @@ -185,7 +185,7 @@ void REC_testCreateBigSession(void) input_length = atoi(user_input); for (hex_idx = 0; hex_idx < input_length; hex_idx++) { - rand_byte = random(256); + rand_byte = SF::utils::random(0, 256); switch (pRecorder->putBytes(&rand_byte, 1)) { case 0: diff --git a/src/util.cpp b/src/util.cpp index 54ad37e..16533b3 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,20 +1,19 @@ /** * @file util.cpp * @author Emily Thorpe (ethorpe@macalster.edu) - * @brief + * @brief * @version 0.1 * @date 2023-07-26 - * + * * @copyright Copyright (c) 2023 - * + * */ - #include "util.hpp" +#include "Particle.h" #include "cli/conio.hpp" #include "consts.hpp" - -#include "Particle.h" +#include "product.hpp" /** * \brief A macro that stores the the size of each line of output as a constant 16 bytes @@ -62,4 +61,13 @@ void hexDump(const void *memoryLocation, size_t buflen) SF_OSAL_printf(" |%s|" __NL__, (const char*)byte_buffer); } SF_OSAL_printf("%08x" __NL__, buffer_idx); +} + +int SF::utils::random(int min, int max) +{ +#if SF_PLATFORM == SF_PLATFORM_PARTICLE + return ::random(min, max); +#elif SF_PLATFORM == SF_PLATFORM_GCC +#error +#endif } \ No newline at end of file diff --git a/src/util.hpp b/src/util.hpp index 36334c9..2864b23 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -17,4 +17,15 @@ void hexDump(const void *memoryLocation, size_t buflen); #define B_TO_N_ENDIAN_2(x) N_TO_B_ENDIAN_2(x) #define B_TO_N_ENDIAN_4(x) N_TO_B_ENDIAN_4(x) +namespace SF::utils +{ + /** + * @brief Generates a uniform random number in the given range + * + * @param min Minimum value (inclusive) + * @param max Maximum value (exclusive) + * @return int random integer + */ + int random(int min, int max); +}; // namespace SF::utils #endif