summaryrefslogtreecommitdiff
path: root/lib/rand.c
blob: 76f537d68d558600bef91cb7ba90e75a7e59591b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

#include <assert.h>
#include <stdio.h>

unsigned long int rand_seed() {
  /*
    returns a random unsigned long integer read from the standard unix
    pseudorandom device /dev/urandom
  */

  FILE *f = fopen("/dev/urandom", "r");
  assert(f != NULL);

  unsigned long int seed;
  fread(&seed, sizeof(unsigned long int), 1, f);

  fclose(f);

  return seed;
}