io.random: bit faster using set-nth-unsafe.
parent
a0d1c036ea
commit
f835bb01f4
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license
|
! See http://factorcode.org/license.txt for BSD license
|
||||||
|
|
||||||
USING: combinators fry io kernel locals math math.order random
|
USING: combinators fry io kernel locals math math.order random
|
||||||
sequences ;
|
sequences sequences.private ;
|
||||||
|
|
||||||
IN: io.random
|
IN: io.random
|
||||||
|
|
||||||
|
@ -19,10 +19,10 @@ PRIVATE>
|
||||||
:: random-lines ( n -- lines )
|
:: random-lines ( n -- lines )
|
||||||
V{ } clone :> accum
|
V{ } clone :> accum
|
||||||
[| line line# |
|
[| line line# |
|
||||||
line# n <=> {
|
line# n <= [
|
||||||
{ +lt+ [ line accum push ] }
|
line accum push
|
||||||
{ +eq+ [ line accum [ push ] [ randomize drop ] bi ] }
|
] [
|
||||||
{ +gt+ [ line# random :> r
|
line# random :> r
|
||||||
r n < [ line r accum set-nth ] when ] }
|
r n < [ line r accum set-nth-unsafe ] when
|
||||||
} case
|
] if
|
||||||
] each-numbered-line accum ;
|
] each-numbered-line accum ;
|
||||||
|
|
Loading…
Reference in New Issue