Changeset 37009 in project


Ignore:
Timestamp:
12/16/18 21:12:55 (6 months ago)
Author:
kon
Message:

better shuffle

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/amb/trunk/amb.scm

    r37006 r37009  
    159159
    160160(use
    161   (only chicken fx= fx+ fx- fxmod)
     161  (only chicken arithmetic-shift fx= fx+ fx- fxmod)
    162162  (only extras random))
    163163(define platform-random random)
     164
     165(define (integer-length n)
     166  (do (
     167        (i 1 (add1 i))
     168        (n (arithmetic-shift n -1) (arithmetic-shift n -1)) )
     169      ((zero? n) i) ) )
    164170
    165171(: vector-shuffle! ((vector-of *) #!optional (procedure (fixnum) fixnum) -> void))
     
    174180        (vector-set! vec i (vector-ref vec i+1))
    175181        (vector-set! vec i+1 tmp) ) )
    176     (do ((n len (fx- n 1)))
     182    (do ((n (integer-length len) (fx- n 1)))
    177183        ((fx= n 0))
    178184      (swap-adj! (rnd len)) ) ) )
Note: See TracChangeset for help on using the changeset viewer.