in reply to Re^24: Why is the execution order of subexpressions undefined?
in thread Why is the execution order of subexpressions undefined?

But a shuffle is nothing but a mapping of array indicies to indicies. So you can eliminate all the memory churn associated with your update in place scheme. It'll be faster in Perl or your functional language of choice. The shuffle routine will, of course, have to be parameterized for the length of array you are using. Its definition is left as an exercise for the reader).
$size = @big_array for (0..$size) { print $big_array[shuffle($_,$size)]; }

Replies are listed 'Best First'.
Re^26: Why is the execution order of subexpressions undefined?
by BrowserUk (Patriarch) on Apr 18, 2005 at 01:32 UTC

    You mean something like this?

    #! perl -slw use strict; $|++; warn 'Start : '.localtime() .$/; my $data = do{ local $/; <> }; warn 'Read : '.localtime() .$/; my $lines = $data =~tr[\n][\n]; my $idx = chr(0) x ( 4 * $lines ); my( $i, $p ) = ( 1, 0 ); substr( $idx, 4*$i++, 4 ) = pack 'N', $p while $p = 1+index $data, $/, $p; my $n = $lines; for my $p ( 0 .. $n-1 ) { my $next = $p + int rand( $n-- ); my $t = substr( $idx, $p*4, 4 ); substr( $idx, $p*4, 4 ) = substr( $idx, $next*4, 4 ); substr( $idx, $next*4, 4 ) = $t; } warn 'Shuffled: '.localtime().$/; printf substr( $data, unpack( 'N', substr( $idx, 4*$_, 4 ) ), index( $data, $/, $_+1 ) - $_ + 1 ) for 0 .. $lines; warn 'Written : '.localtime().$/;

    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?