Skip to content

Commit

Permalink
Revert "Fix #10; skipping final bit in flip.c"
Browse files Browse the repository at this point in the history
This reverts commit 0b143a0.
  • Loading branch information
fsaad committed Feb 25, 2024
1 parent 195b4cd commit f7ba81d
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions src/c/flip.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,15 @@

#include "flip.h"

static int k = 31;
static int k = 30;
static int flip_word = 0;
static int flip_pos = 31;
static int flip_pos = 0;

int flip(void){
if (flip_pos == k) {
if (flip_pos == 0) {
flip_word = rand();
flip_pos = 0;
flip_pos = k;
}
return (flip_word >> flip_pos++) & 1;
--flip_pos;
return (flip_word >> flip_pos) & 1;
}

// Old implementation scans from lower-to-higher order bits,
// but rand() has poor quality on lower order bits.
// int flip(void){
// static int k = 31;
// static int flip_word = 0;
// static int flip_pos = 0;
// if (flip_pos == 0) {
// flip_word = rand();
// flip_pos = k;
// }
// return (flip_word >> --flip_pos) & 1;
// }

0 comments on commit f7ba81d

Please sign in to comment.