summaryrefslogtreecommitdiff
path: root/random.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-04-24 09:33:30 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-04-24 09:33:30 +0000
commit9ce253a2cfc26cc7a0d2cfeeaf15d6216d522077 (patch)
tree6f6334590a5705de7f7288d3eb8e572bfe75453f /random.c
parent8581fa1549787fc64e0d8a198838fe47104726c1 (diff)
gtk/nested local variables
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'random.c')
-rw-r--r--random.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/random.c b/random.c
index 8674dd0bad..7902658fbd 100644
--- a/random.c
+++ b/random.c
@@ -12,8 +12,22 @@
#include "ruby.h"
+#include <time.h>
+#ifndef NT
+#ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+#else
+struct timeval {
+ long tv_sec; /* seconds */
+ long tv_usec; /* and microseconds */
+};
+#endif
+#endif /* NT */
+
static int first = 1;
+#ifdef HAVE_RANDOM
static char state[256];
+#endif
static VALUE
f_srand(argc, argv, obj)
@@ -26,7 +40,10 @@ f_srand(argc, argv, obj)
static int saved_seed;
if (rb_scan_args(argc, argv, "01", &seed) == 0) {
- seed = time(0);
+ struct timeval tv;
+
+ gettimeofday(&tv, 0);
+ seed = tv.tv_usec;
}
else {
seed = NUM2INT(seed);
@@ -61,12 +78,9 @@ f_rand(obj, vmax)
{
int val, max;
-#ifdef HAVE_RANDOM
if (first == 1) {
- initstate(1, state, sizeof state);
- first = 0;
+ f_srand(0, 0, 0);
}
-#endif
switch (TYPE(vmax)) {
case T_BIGNUM: