deadbeef_rand Documentation

This is the documentation for deadbeef_rand, a simple pseudo-random number generator. This code is part of Inglorion's CStuff.

The deadbeef random number generator is a pseudo-random number generator. Pseudo-random numbers are numbers that look random, but aren't. This means deadbeef_rand should not be used in cases where true random numbers are required. However, there are plenty of applications where deadbeef_rand's pseudo-random numbers are good enough. The numbers generated by deadbeef_rand have the following properties:

The deadbeef random number generator is very fast and seems to perform relatively well on a number of tests for random number generators. See the deadbeef random number generator webpage for more details.

To use deadbeef_rand, you must first seed the generator by calling deadbeef_srand(). You can then get 32-bit pseudo-random numbers by calling deadbeef_rand(). The sequence of numbers generated is fully determined by the seed passed to deadbeef_srand(); that is, using the same seed twice will cause deadbeef_rand() to emit the same sequence of numbers twice. This is useful in some cases, and undesirable in others.

There are two main starting points for using the documentation:

Meanwhile, here is a small usage example:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "deadbeef_rand.h"

/* This function generates a seed for the random number
 * generator. Ideally, it would generate a different value for every run
 * of the program. For purposes of this example, the function is kept
 * short.
 */
uint32_t generate_seed() {
  uint32_t t = (uint32_t) time(NULL);
  uint32_t c = (uint32_t) clock();
  return (t << 24) ^ (c << 11) ^ t ^ (uint32_t) &c;
}

int main(int argc, char **argv) {
  /* Seed the random number generator. */
  deadbeef_srand(generate_seed());

  /* Generate and print endless stream of random numbers. */
  while(1) {
    printf("%u\n", deadbeef_rand());
  }

  return 0;
}

Generated on Thu Dec 6 14:01:04 2007 for deadbeef_rand by  doxygen 1.5.1