Paste: randomize

Author: mrjbq7
Mode: factor
Date: Thu, 25 Sep 2008 20:02:33
Plain Text |
USING: math.ranges kernel random ;

: switch ( to from seq -- )
    3dup swap [ nth ] dip [ [ move ] keep ] 2dip rot set-nth ;

: randomize ( seq -- seq' )
    dup length 1-
    [ dup 1 > ] [
        [ [0,b) random ] keep dup 
        [ rot [ switch ] keep ] dip 1-
    ] [ drop ] while ;
    

Annotation: randomize (using "exchange")

Author: mrjbq7
Mode: factor
Date: Thu, 25 Sep 2008 20:12:55
Plain Text |
: randomize ( seq -- seq' )
    dup length 1-
    [ dup 1 > ] [
        [ [0,b) random ] keep dup 
        [ rot [ exchange ] keep ] dip 1-
    ] [ drop ] while ;

Annotation: randomize2

Author: erg
Mode: factor
Date: Thu, 25 Sep 2008 20:19:55
Plain Text |
: randomize2 ( seq -- seq' ) 
    dup length 1 swap [a,b) <reversed> [ dup random pick exchange ] each ;

Annotation: alternative randomize

Author: erg
Mode: factor
Date: Thu, 25 Sep 2008 20:19:58
Plain Text |
: randomize2 ( seq -- seq' )
    dup length 1 swap [a,b) <reversed> [ dup random pick exchange ] each ;

Annotation: even better

Author: slava
Mode: factor
Date: Thu, 25 Sep 2008 21:17:03
Plain Text |
: radomize3 ( seq -- seq' )
    dup length 1 (a,b] [ dup random pick exchange ] each ;

New Annotation

Summary:
Author:
Mode:
Body: