deadbeef_rand.h File Reference


Detailed Description

The public interface to the deadbeef random number generator.

This file contains the public interface to the deadbeef random number generator. For documentation of everything, including things meant only for internal use, see deadbeef_rand.c.

The following is a usage example of the interface defined in this file:

#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;
}

Definition in file deadbeef_rand.h.

#include <inttypes.h>

Go to the source code of this file.

Functions

uint32_t deadbeef_rand ()
 Generate a 32-bit random number.
void deadbeef_srand (uint32_t x)
 Seed the deadbeef random number generator.


Function Documentation

uint32_t deadbeef_rand (  ) 

Generate a 32-bit random number.

Before using this function, you should seed the generator by calling deadbeef_srand().

Definition at line 11 of file deadbeef_rand.c.

void deadbeef_srand ( uint32_t  seed  ) 

Seed the deadbeef random number generator.

Starting from the same seed, multiple runs of the deadbeef random number generator will generate identical sequences of pseudo-random numbers. This is sometime useful. In cases where it is desirable to have different runs of the generator generate different sequences, you should seed them with different seeds.

Parameters:
seed The value to seed the deadbeef generator with

Definition at line 27 of file deadbeef_rand.c.


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