> On Jan 25, 2008, at 11:01 AM, After Hours wrote:
>
>> I have an unusual need to randomize a text file with about 500
>> lines (defined by CR line endings).
>>
>> Is there a method I've not discovered in BBEdit that will randomize
>> such a text file?
>
> You can do it with a Unix filter. Here's one in PERL (which I found
> on the web at some point). Just save it in your Unix Filters folder,
> then select the lines you want to randomize and run the filter.
>
> #!/usr/bin/perl -w
>
> sub fys {
> my $array=shift;
> my $i;
> for ( [EMAIL PROTECTED]; --$i; ) {
> my $j = int rand ($i+1);
> next if $i == $j;
> @$array[$i,[EMAIL PROTECTED],$i];
> }
> }
>
> while (<>) {
> push(@lines, $_);
> }
> fys([EMAIL PROTECTED]);
> foreach(@lines) {
> print $_;
> }
Or a little shorter:
**************************************
#!/usr/bin/perl -w
@content = <>;
while (@content) { print splice(@content,rand(@content),1); }
**************************************
- B
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to: <[EMAIL PROTECTED]>