Ignore:
Timestamp:
Dec 23, 2009, 12:28:27 AM (10 years ago)
Author:
rme
Message:

On Windows, use quasi-documented function RtlGenRandom? to initialize
random state object when calling (make-random-state t).

http://msdn.microsoft.com/en-us/library/aa387694(VS.85).aspx
http://blogs.msdn.com/michael_howard/archive/2005/01/14/353379.aspx

File:
1 edited

Legend:

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

    r13333 r13334  
    456456    (%cons-mrg31k3p-state x0 x1 x2 x3 x4 x5)))
    457457
     458#+windows-target
     459(defun random-mrg31k3p-state ()
     460  (flet ((random-u32 ()
     461           (%stack-block ((buf 4))
     462             ;; BOOLEAN RtlGenRandom(PVOID buf, ULONG len)
     463             (let ((r (external-call "SystemFunction036" :address buf
     464                                     :unsigned 4 :byte)))
     465               (if (plusp r)
     466                 (%get-unsigned-long buf)
     467                 (init-random-state-seeds))))))
     468    (loop repeat 6
     469          for n = (random-u32)
     470          ;; The first three seed elements must not be all zero, and
     471          ;; likewise for the second three.  Avoid the issue by
     472          ;; excluding zero values.
     473          collect (1+ (mod n (1- mrg31k3p-limit))) into seed
     474          finally (return (apply #'%cons-mrg31k3p-state seed)))))
     475
     476#-windows-target
    458477(defun random-mrg31k3p-state ()
    459478  (with-open-file (stream "/dev/urandom" :element-type '(unsigned-byte 32)
Note: See TracChangeset for help on using the changeset viewer.