1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tools/reorder/rseed.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,33 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +/* 1.9 + 1.10 + A program that reads /dev/random to produce a seed for srand(3). 1.11 + 1.12 + */ 1.13 + 1.14 +#include <stdio.h> 1.15 +#include <fcntl.h> 1.16 + 1.17 +int 1.18 +main(int argc, char *argv[]) 1.19 +{ 1.20 + int fd, ok, seed = 0; 1.21 + 1.22 + fd = open("/dev/random", O_RDONLY); 1.23 + if (fd < 0) { 1.24 + perror("/dev/random"); 1.25 + return 1; 1.26 + } 1.27 + 1.28 + ok = read(fd, &seed, sizeof seed); 1.29 + if (ok > 0) 1.30 + printf("%d\n", seed); 1.31 + else 1.32 + perror("/dev/random"); 1.33 + 1.34 + close(fd); 1.35 + return 0; 1.36 +}