Get seed from /dev/urandom instead of using time(2)
This commit is contained in:
parent
512580ab27
commit
5ae7a18227
19
main.c
19
main.c
@ -18,13 +18,28 @@
|
|||||||
|
|
||||||
#include "sud.h"
|
#include "sud.h"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
|
||||||
|
static uint32_t getseed(void)
|
||||||
|
{
|
||||||
|
FILE *urandom = fopen("/dev/urandom", "rb");
|
||||||
|
if (urandom == NULL)
|
||||||
|
fprintf(stderr, "Failed to open /dev/urandom\n");
|
||||||
|
|
||||||
|
uint32_t seed = 0;
|
||||||
|
for (unsigned i = 0; i < 4; ++i)
|
||||||
|
seed = seed << 8 | fgetc(urandom);
|
||||||
|
|
||||||
|
fclose(urandom);
|
||||||
|
|
||||||
|
return seed;
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
unsigned seed = time(NULL);
|
uint32_t seed = getseed();
|
||||||
printf("Seed: %u\n\n", seed);
|
printf("Seed: %u\n\n", seed);
|
||||||
srand(seed);
|
srand(seed);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user