/[cmucl]/src/code/rand.lisp
ViewVC logotype

Diff of /src/code/rand.lisp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.9 by dtc, Thu Jun 5 00:20:52 1997 UTC revision 1.9.2.1 by dtc, Tue Sep 9 00:44:16 1997 UTC
# Line 239  Line 239 
239  #+new-random  #+new-random
240  (in-package "KERNEL")  (in-package "KERNEL")
241  #+new-random  #+new-random
242  (export '(%random-single-float %random-double-float random-chunk-max))  (export '(%random-single-float %random-double-float))
243    
244    
245  #+new-random  #+new-random
# Line 479  Line 479 
479    
480  ;;;; Random integers:  ;;;; Random integers:
481    
482  ;;; We generate a random float and extract this many bits from it. The  ;;; Random integers are created by concatenating a bunch of chunks
483  ;;; random integer is created by concatenating a bunch of these  ;;; together. Chunks are generated without consing by truncating a
484  ;;; together.  31 has the nice property that Python doesn't have to  ;;; random float to an integer. With the latest propagate-float-type
485  ;;; box it up, and that Python can optimize the truncate call because  ;;; code the compiler can inline truncate (signed-byte 32) allowing 31
486  ;;; the result is a (signed-byte 32).  ;;; bits, and (unsigned-byte 32) 32 bits on the x86. When not using the
487    ;;; propagate-float-type feature the best size that can be inlined is
488    ;;; 29 bits.  Use of sizes greater than 29 bits causes consing in
489    ;;; argument passing to generic functions, so 29 bits is a good
490    ;;; default.
491  ;;;  ;;;
492  (defconstant random-chunk-size 29)  (defconstant random-chunk-size 29)
 (defconstant random-chunk-max (1- (expt 2 random-chunk-size)))  
493    
494  ;;; %RANDOM-INTEGER -- Internal  ;;; %RANDOM-INTEGER -- Internal
495  ;;;  ;;;
# Line 497  Line 500 
500    (declare (type (integer 1) arg)    (declare (type (integer 1) arg)
501             (type random-state state))             (type random-state state))
502    (flet ((random-chunk (state)    (flet ((random-chunk (state)
503             (values (truncate (* (float (1+ random-chunk-max) 1d0)             (values (truncate (* (float (expt 2 random-chunk-size) 1d0)
504                                  (new-random-float state))))))                                  (new-random-float state))))))
505      (let ((shift random-chunk-size))      (let ((shift random-chunk-size))
506        (do ((bits (random-chunk state)        (do ((bits (random-chunk state)

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.9.2.1

  ViewVC Help
Powered by ViewVC 1.1.5