/* * 'dev_rand.c' created: Thu Oct 17 14:15:19 2002 * * Copyright 2002 by Lubomir Host <8host AT pauli.fmph.uniba.sk> * * License: GNU GPL (GNU Public License) * */ /* $Platon$ */ #ifdef HAVE_CONFIG_H # include "config.h" #endif #include #include #include #include #include #include #include #include "dev_rand.h" RNG_device_t rng_dev_rand = { "rand()", -1, 0, 1E9, UINT_MAX, 11, /* 2^12 = 4096 random numbers per 1 cell */ open_dev_rand, read_dev_rand, close_dev_rand }; int open_dev_rand(void) { int fd; int count; unsigned int seed; if ((fd = open("/dev/urandom", O_RDONLY)) == -1) { fprintf(stderr, "Initialization of rand() failed!\n"); return RNG_FAIL; } count = read(fd, &seed, sizeof(unsigned int)); if (count != sizeof(unsigned int)) { fprintf(stderr, "Read from /dev/urandom for initializaiton " "of rand() failed !\n"); return RNG_FAIL; } close(fd); srand(seed); return RNG_OK; } Real_t read_dev_rand(void) { return rand(); } int close_dev_rand(void) { return RNG_OK; } /* Modeline for ViM {{{ * vim: set ts=4: * vim600: fdm=marker fdl=0 fdc=3: * }}} */