Skip to content

Commit

Permalink
added random_int
Browse files Browse the repository at this point in the history
  • Loading branch information
Dpbm committed Feb 2, 2024
1 parent 557a787 commit 15ad431
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion helpers/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ namespace Utils {
return distr(eng);
}

unsigned int random_int(int start, int end){
std::random_device device;
std::mt19937 eng(device());
std::uniform_int_distribution<> distr(start, end);

return distr(eng);
}

unsigned int get_random_pos(unsigned int max_range, unsigned int factor){
unsigned int rand = Utils::random(0, max_range);
unsigned int rand = Utils::random_int(0, max_range);
return rand-(rand%factor);
}

Expand Down
1 change: 1 addition & 0 deletions helpers/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ using std::string;
namespace Utils {
unsigned int get_random_pos(unsigned int max_range, unsigned int factor);
double random(int start, int end);
unsigned int random_int(int start, int end);
bool passed_debounce_time(int last_tick);
void append_to_file(string filename, string data);
void create_file(string filename, string data);
Expand Down

0 comments on commit 15ad431

Please sign in to comment.