[REBOL] Re: Question and comment about randomizing a block of values
From: agem:crosswinds at: 19-Jun-2001 4:51
RE: [REBOL] Re: Question and comment about randomizing a block of values
[joel--neely--fedex--com] wrote:
> Hi, Volker,
>
> [agem--crosswinds--net] wrote:
> >
> >
> > usualy i shuffle like this:
> > [rebol []
> > n-cards: 20
> > deck: copy []
> > repeat i n-cards [append deck i]
> > probe deck
> >
> > random/seed now
> > shuffled-deck: copy []
> > loop n-cards [
> > card-no: random length? deck
> > append shuffled-deck pick deck card-no
> > remove at deck card-no
> > ]
> > probe shuffled-deck
> > ]
> >
>
> It probably doesn't matter for small blocks, but I suspect the
> overhead of plucking a value out of the middle of a block
> (presuming that the following elements are scooted over to fill
> the gap) might add up for larger blocks. That's one of the
> reasons I proposed building a result without modifying the
> original. Some benchmarking is probably in order to see whether
> my suspicions are valid or total nonsense (both have been known
> to happen ;-).
>
its in my trick-bag now. :) but card-games, ~50?
performance-hint for great blocks: don't use remove.
poke deck card-no (last deck) clear back tail deck
random is random i hope? ;-)
;clear can be ommitted with downcounting loop..
-Volker