jeudi 15 novembre 2018

How can I use PractRand to test a PRNG that ranges from $0$ to $2^15 - 1$?

PractRand sees the input as a string of bits. If I use an unsigned short int and write the output of the PRNG in binary to the stdin, then the MSb will always be zero and PractRand will unfairly say it fails [Low1/8]DC6-9x1Bytes-1.

Here's the PRNG. (That's K&R's PRNG.)

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
  unsigned int random;
  srand(1);
  for (;;) {
    random = rand();
    fwrite(&random, sizeof random, 1, stdout);
  }
}

It seems the problem is that fwrite takes the number of bytes to write and not bits, so I'm not sure how I could workaround this in a simple fashion.




Aucun commentaire:

Enregistrer un commentaire