Changeset 7237


Ignore:
Timestamp:
Sep 17, 2007, 11:53:12 AM (12 years ago)
Author:
gb
Message:

Simply clearing the top bit of the intermediate result from
%NEXT-RANDOM-PAIR had the effect of using doing (mod result (expt 2
31)), not (mod result (1- (expt 2 31))). Do a real MOD to obtain the
next item in the series and update the state with that value.
(This means that the high bit of the high half of the result is always
clear; or in the sign bit from the low half.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/level-0/l0-numbers.lisp

    r7136 r7237  
    17811781#+64-bit-target
    17821782(defun %next-random-pair (high low)
    1783   (let* ((n (nth-value
    1784              1
    1785              (%multiply 48271 (dpb (ldb (byte 15 0) high)
    1786                                       (byte 16 16)
    1787                                       (ldb (byte 16 0) low ))))))
    1788     (values (ldb (byte 16 16) n)
     1783  (declare (type (unsigned-byte 16) high low))
     1784  (let* ((n0
     1785          (%i* 42871
     1786             (the  (unsigned-byte 31)
     1787               (logior (the (unsigned-byte 31)
     1788                         (ash (ldb (byte 15 0) high) 16))
     1789                       (the (unsigned-byte 16)
     1790                         (ldb (byte 16 0) low))))))
     1791         (n (fast-mod n0 (1- (expt 2 31)))))
     1792    (declare (fixnum n))
     1793    (values (ldb (byte 15 16) n)
    17891794            (ldb (byte 16 0) n))))
    17901795
     
    17921797  (multiple-value-bind (high low) (%next-random-pair (%svref state 1)
    17931798                                                     (%svref state 2))
    1794     (setf (%svref state 1) (ldb (byte 15 0) high)
     1799    (declare (type (unsigned-byte 15) high)
     1800             (type (unsigned-byte 16) low))
     1801    (setf (%svref state 1) high
    17951802          (%svref state 2) low)
    1796     high
    1797     ))
     1803    (logior high (the fixnum (logand low (ash 1 15))))))
    17981804
    17991805
Note: See TracChangeset for help on using the changeset viewer.