From: Chris Hanson Date: Mon, 9 Aug 1999 19:08:50 +0000 (+0000) Subject: If /dev/random is available, use it to seed the PRNG. X-Git-Tag: 20090517-FFI~4488 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=3520a2229262955d9755d1459e03fc031e053262;p=mit-scheme.git If /dev/random is available, use it to seed the PRNG. --- diff --git a/v7/src/runtime/random.scm b/v7/src/runtime/random.scm index 0cd61df3a..2a19e7317 100644 --- a/v7/src/runtime/random.scm +++ b/v7/src/runtime/random.scm @@ -1,6 +1,6 @@ #| -*-Scheme-*- -$Id: random.scm,v 14.18 1999/01/02 06:11:34 cph Exp $ +$Id: random.scm,v 14.19 1999/08/09 19:08:50 cph Exp $ Copyright (c) 1993-1999 Massachusetts Institute of Technology @@ -91,7 +91,20 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. (let ((state (if (default-object? state) #f state))) (if (or (eq? #t state) (int:integer? state)) (initial-random-state - (congruential-rng (+ (real-time-clock) 123456789))) + (congruential-rng + ;; Use good random source if available + (if (file-exists? "/dev/urandom") + (call-with-input-file "/dev/urandom" + (lambda (port) + (let* ((b1 (char->integer (read-char port))) + (b2 (char->integer (read-char port))) + (b3 (char->integer (read-char port))) + (b4 (char->integer (read-char port)))) + (+ (* b1 #x1000000) + (* b2 #x10000) + (* b3 #x100) + b4)))) + (+ (real-time-clock) 123456789)))) (copy-random-state (guarantee-random-state state 'MAKE-RANDOM-STATE)))))