Changeset 13333


Ignore:
Timestamp:
Dec 22, 2009, 10:35:55 PM (10 years ago)
Author:
rme
Message:

If the system has /dev/urandom, read from it to initialize the
random-state object when calling (make-random-state t).

Use different values for the intial random state.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/level-1/l1-numbers.lisp

    r13327 r13333  
    457457
    458458(defun random-mrg31k3p-state ()
    459   (loop repeat 6
    460         for n = (init-random-state-seeds)
    461         ;; The first three seed elements must not be all zero, and
    462         ;; likewise for the second three.  Avoid the issue by
    463         ;; excluding zero values.
    464         collect (1+ (mod n (1- mrg31k3p-limit))) into seed
    465         finally (return (apply #'%cons-mrg31k3p-state seed))))
     459  (with-open-file (stream "/dev/urandom" :element-type '(unsigned-byte 32)
     460                          :if-does-not-exist nil)
     461    (loop repeat 6
     462          for n = (if stream (read-byte stream) (init-random-state-seeds))
     463          ;; The first three seed elements must not be all zero, and
     464          ;; likewise for the second three.  Avoid the issue by
     465          ;; excluding zero values.
     466          collect (1+ (mod n (1- mrg31k3p-limit))) into seed
     467          finally (return (apply #'%cons-mrg31k3p-state seed)))))
    466468
    467469(defun initial-random-state ()
    468   (initialize-mrg31k3p-state 12345 12345 12345 12345 12345 12345))
     470  (initialize-mrg31k3p-state 314159 42 1776 271828 6021023 1066))
    469471
    470472(defun make-random-state (&optional state)
Note: See TracChangeset for help on using the changeset viewer.