michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: michael@0: A program that reads /dev/random to produce a seed for srand(3). michael@0: michael@0: */ michael@0: michael@0: #include michael@0: #include michael@0: michael@0: int michael@0: main(int argc, char *argv[]) michael@0: { michael@0: int fd, ok, seed = 0; michael@0: michael@0: fd = open("/dev/random", O_RDONLY); michael@0: if (fd < 0) { michael@0: perror("/dev/random"); michael@0: return 1; michael@0: } michael@0: michael@0: ok = read(fd, &seed, sizeof seed); michael@0: if (ok > 0) michael@0: printf("%d\n", seed); michael@0: else michael@0: perror("/dev/random"); michael@0: michael@0: close(fd); michael@0: return 0; michael@0: }