view src/ploki/random.c @ 11626:4da3722c4cb6 draft

<wob_jonas> `` rm -v allsets-*.txt; gzip -dc share/mtg/allsets-2018-05-21.zip > share/mtg/allsets-2018-05-21.txt
author HackEso <hackeso@esolangs.org>
date Fri, 05 Oct 2018 15:43:14 +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);
}