view src/ploki/random.c @ 10513:28c4c6b6e9bd

<wob_jonas> `` sed -i \'s/M3/Saw Gerrera|Shmi|Sio Bibble|Sith Lord Jar Jar|Supreme Leader Snoke|Taun We|Watto|Wedge Antilles|Willard|Yoda|Zam Wessel|the Dianoga|the Rancor|the Sarlacc/\' bin/starwars && cat bin/starwars
author HackBot
date Sun, 26 Mar 2017 02:00:49 +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);
}