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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|