Previous comments were all informative, but I gather you may still be wondering how to deal with 80 columns or so of data... You want to transpose the CSV array, so that each column is stored in its own array so you can shuffle it.

I tried the following on (a copy of) a csv dump of my last bank statement -- seems to do the job (could make taxes interesting this year...)

BTW, I suppose Fisher_Yates is good enough, but my own favorite has always been to prepend a random number to the string (default output of rand() is between 0.0 and 0.999...), then sort, then remove the random number.

use strict; my @transpose; # this will be an array of arrays my $ncols = 0; while (<>) { chomp; my @cols = split(/,/); if ( $ncols ) { die "Line $. doesn't have $ncols columns\n" if ( $ncols != scalar @cols ); } else { $ncols = scalar @cols; } foreach my $i (0..$#cols) { push( @{$transpose[$i]}, $cols[$i] ); } } my $nrows = $.; for (0..$ncols-1) { &fisher_yates_shuffle( $transpose[$_] ); } foreach my $i (0..$nrows-1) { my @cols = (); foreach my $j (0..$ncols-1) { push( @cols, $transpose[$j][$i] ); } print join( ",", @cols ) . "\n"; }

In reply to Re: Randomize CSV word lists by graff
in thread Randomize CSV word lists by Grendel2112

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.