Skip to content

Commit

Permalink
feat: Adds utils random
Browse files Browse the repository at this point in the history
ntlhui committed Dec 13, 2024
1 parent 6e82ea3 commit c4126e1
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/debug/recorder_debug.cpp
Original file line number Diff line number Diff line change
@@ -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:
20 changes: 14 additions & 6 deletions src/util.cpp
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 11 additions & 0 deletions src/util.hpp
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c4126e1

Please sign in to comment.