view src/ploki/random.c @ 4225:4c30f3005bab

<oerjan> addquote <Taneb> Well, get him <Phantom_Hoover> her! <Taneb> Well, get her <Taneb> Hang on <Taneb> Since when is Liam Neeson a "her"/ <Phantom_Hoover> oh i thought you meant my dad\'s godmother
author HackBot
date Wed, 25 Dec 2013 13:31:15 +0000
parents ac0403686959
children
line wrap: on
line source

#include "config.h"
#include "random.h"

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

void randseed(void) {
	unsigned seed;

	seed = time(NULL);
	#if HAVE_DEV_URANDOM_P
	{
		FILE *fp;

		if ((fp = fopen("/dev/urandom", "rb"))) {
			fread(&seed, sizeof seed, 1, fp);
			fclose(fp);
		}
	}
	#endif
	srand(seed);
}

double randval(void) {
	return rand() / (RAND_MAX + 1.0);
}