[REBOL] Re: Question and comment about randomizing a block of values
From: agem:crosswinds at: 19-Jun-2001 0:47
RE: [REBOL] Question and comment about randomizing a block of values
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> Hey all!
> I'm working on a set of generic class's to be used to create card
> based games. (current framework included below)
> My question centers on 'shuffling' the deck. I know there are _many_
> methods of shuffling, with various degrees of randomness. I'd like to
> know what you all think about the following 'shuffle' function (this
> function is in a class. the list-of-cards var is a class variable):
> shuffle-deck: func [ "Randomizes the list-of-cards"
> number-of-passes [number!]
> ] [
> for a-pass 1 number-of-passes 1 [
> sort/compare list-of-cards func [a b /local c] [
> c: random 2
> if c = 1 [return true]
> if c = 2 [return false]
> Using the sort/compare works really fast, but i'm not sure that this
> is the way its meant to be used ;), but it seems to work quite well,
> especially with multiple passes. If anyone has any suggestions,
> please let me know!
:) :) :) funny way
usualy i shuffle like this:
deck: copy 
repeat i n-cards [append deck i]
shuffled-deck: copy 
loop n-cards [
card-no: random length? deck
append shuffled-deck pick deck card-no
remove at deck card-no
also Allan Kamp has some nice card-games.
on http://www.rebolforces.com/index.r , reb-sites/R-forces .
maybe he should start some article about it?
BTW Allan, where are the RebNotes gone?!