Skip to content

Commit

Permalink
Marbles: Fix bug where a random event could happen with deja vu = 0.5
Browse files Browse the repository at this point in the history
This bug can happen only extremely rarely: when `deja_vu_` is 0.5 and
`random_stream_` produces a zero. It's not clear from the MCU
datasheet or reference manual whether the hardware RNG is capable of
producing zeros, but the fallback `RandomGenerator` LCG certainly will
given enough time.
  • Loading branch information
float32 committed Jul 3, 2021
1 parent 3c3d177 commit cf45887
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions marbles/random/random_sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class RandomSequence {
const float p = p_sqrt * p_sqrt;
float rho = random_stream_->GetFloat();

if (rho <= p && deja_vu_ <= 0.5f) {
if (rho < p && deja_vu_ <= 0.5f) {
// Generate a new value and put it at the end of the loop.
redo_write_ptr_ = &loop_[loop_write_head_];
*redo_write_ptr_ = deterministic
Expand All @@ -179,7 +179,7 @@ class RandomSequence {
// Do not generate a new value, just replay the loop or jump randomly.
// through it.
redo_write_ptr_ = NULL;
if (rho <= p) {
if (rho < p) {
step_ = static_cast<int>(
random_stream_->GetFloat() * static_cast<float>(length_));
} else {
Expand Down

0 comments on commit cf45887

Please sign in to comment.