Back to index

lightning-sunbird  0.9+nobinonly
Functions
prng.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <time.h>
#include <unistd.h>
#include "bbs_rand.h"

Go to the source code of this file.

Functions

int main (int argc, char *argv[])

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 57 of file prng.c.

{
  unsigned char *seed;
  unsigned int   ix, num = 1;
  pid_t          pid;
  
  if(argc > 1) {
    num = atoi(argv[1]);
    if(num <= 0) 
      num = 1;
  }

  pid = getpid();
  srand(time(NULL) * (unsigned int)pid);

  /* Not a perfect seed, but not bad */
  seed = malloc(bbs_seed_size);
  for(ix = 0; ix < bbs_seed_size; ix++) {
    seed[ix] = rand() % UCHAR_MAX;
  }

  bbs_srand(seed, bbs_seed_size);
  memset(seed, 0, bbs_seed_size);
  free(seed);

  while(num-- > 0) {
    ix = bbs_rand();

    printf("%u\n", ix);
  }

  return 0;

}

Here is the call graph for this function: