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
|
||||
|
||||
USING: combinators fry io kernel locals math math.order random
|
||||
sequences ;
|
||||
sequences sequences.private ;
|
||||
|
||||
IN: io.random
|
||||
|
||||
|
@ -19,10 +19,10 @@ PRIVATE>
|
|||
:: random-lines ( n -- lines )
|
||||
V{ } clone :> accum
|
||||
[| line line# |
|
||||
line# n <=> {
|
||||
{ +lt+ [ line accum push ] }
|
||||
{ +eq+ [ line accum [ push ] [ randomize drop ] bi ] }
|
||||
{ +gt+ [ line# random :> r
|
||||
r n < [ line r accum set-nth ] when ] }
|
||||
} case
|
||||
line# n <= [
|
||||
line accum push
|
||||
] [
|
||||
line# random :> r
|
||||
r n < [ line r accum set-nth-unsafe ] when
|
||||
] if
|
||||
] each-numbered-line accum ;
|
||||
|
|
Loading…
Reference in New Issue