* random.c (random_seed): use /dev/urandom if available.
[ruby-dev:25392] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5ef141e3e9
commit
e5abd52ab2
@ -1,3 +1,8 @@
|
|||||||
|
Mon Jan 3 11:37:42 2005 Tanaka Akira <akr@m17n.org>
|
||||||
|
|
||||||
|
* random.c (random_seed): use /dev/urandom if available.
|
||||||
|
[ruby-dev:25392]
|
||||||
|
|
||||||
Mon Jan 3 11:03:37 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
|
Mon Jan 3 11:03:37 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
|
||||||
|
|
||||||
* test/drb/test_drb.rb: move TestDRbReusePort to new file.
|
* test/drb/test_drb.rb: move TestDRbReusePort to new file.
|
||||||
|
20
random.c
20
random.c
@ -144,6 +144,11 @@ genrand_real()
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#ifdef HAVE_FCNTL_H
|
||||||
|
#include <fcntl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
static int first = 1;
|
static int first = 1;
|
||||||
|
|
||||||
@ -167,9 +172,22 @@ random_seed()
|
|||||||
{
|
{
|
||||||
static int n = 0;
|
static int n = 0;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
unsigned long result;
|
||||||
|
int fd;
|
||||||
|
unsigned long buf;
|
||||||
|
|
||||||
gettimeofday(&tv, 0);
|
gettimeofday(&tv, 0);
|
||||||
return tv.tv_sec ^ tv.tv_usec ^ getpid() ^ n++;
|
result = tv.tv_sec ^ tv.tv_usec ^ getpid() ^ n++;
|
||||||
|
|
||||||
|
result += (unsigned long)&result;
|
||||||
|
|
||||||
|
if ((fd = open("/dev/urandom", O_RDONLY)) >= 0) {
|
||||||
|
read(fd, &buf, sizeof(buf));
|
||||||
|
close(fd);
|
||||||
|
result ^= buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user