Skip to content

Commit

Permalink
Addressed implementation defined behaviour in rng function
Browse files Browse the repository at this point in the history
Properly handle the results of the rng output as unsigned ints, rather than relying on implementation defined conversion from unsigned to signed integers
  • Loading branch information
edo9300 committed Mar 7, 2024
1 parent ffd8ec1 commit 4a64c53
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions duel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ void duel::set_response(const void* resp, size_t len) {
}
// uniform integer distribution
int32_t duel::get_next_integer(int32_t l, int32_t h) {
const int32_t range = h - l + 1;
const int32_t lim = random.max() % range;
int32_t n;
const uint32_t range = h - l + 1;
const uint32_t lim = random.max() % range;
uint32_t n;
do {
n = random();
n = static_cast<uint32_t>(random());
} while(n <= lim);
return static_cast<int32_t>((n % range) + l);
return static_cast<int32_t>(n % range) + l;
}
duel::duel_message* duel::new_message(uint8_t message) {
return &(messages.emplace_back(message));
Expand Down

0 comments on commit 4a64c53

Please sign in to comment.