in reply to Re^2: Random Math Question
in thread Random Math Question

Although any number can end up in any position, without something to break up the groups between repetitions, the groups of numbers will remain grouped:

#! perl -slw use strict; sub by8 { map{ [ @_[ $_*8 .. ( $_ +1 ) *8 - 1 ] ] } shuffle( 0 .. 7 ); } sub shuffle { for ( 0 .. $#_ ) { $a = $_ + rand( @_ )-$_ ; @_[ $_, $a ] = @_[ $a, $_ ] ; } return @_; } sub LRShuffle { map{ shuffle @$_; } by8 @_; } my @list = 0 .. 63; print 'Shuffled Once'; print @$_ for by8 LRShuffle @list; my @times10 = @list; @times10 = LRShuffle @times10 for 1 .. 10; print "\nShuffled 10 times"; print @$_ for by8 @times10; __END__ P:\test>498952 Shuffled Once 50 48 53 51 49 52 55 54 20 23 18 17 22 16 19 21 59 58 56 63 57 62 61 60 25 29 27 31 28 24 26 30 41 45 46 43 47 44 40 42 13 11 9 10 8 15 12 14 38 37 33 35 36 34 32 39 2 4 7 0 5 1 6 3 Shuffled 10 times 14 12 13 11 8 15 10 9 16 21 23 17 22 20 18 19 44 45 40 41 42 47 43 46 6 7 0 5 3 4 2 1 32 38 39 34 36 35 37 33 55 48 53 50 52 49 54 51 59 57 56 58 62 61 63 60 30 25 26 28 24 27 31 29

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Replies are listed 'Best First'.
Re^4: Random Math Question
by jdporter (Paladin) on Oct 11, 2005 at 04:37 UTC
    Just to elaborate on what BrowserUK said — It isn't enough for any given number to have an equal probability of ending up in any position. It has to have an equal probability of ending up in any position irrespective of the positions of any other numbers. Clearly, under this algorithm, the number 1 will never be more than b-1 places away from 2 (where b is the block size). (In fact the constraint is tighter than that, but that's enough description to make the point.)