#!/usr/local/bin/perl use strict; use integer; $!++; my $number=10000; my $num_per_block=10; my $string; my $start=0; my $end=$number-1; vec $string, $end, 1; while ($number) { my $block_size=(($end-$start+1)/$number)*$num_per_block; my $rand=int rand($number+1); my $found=1; # optimist my $guess_block=int($rand / $block_size); my $i=$start+($guess_block*$block_size); my $fiddled_rand=$rand-($guess_block*$num_per_block); while ($fiddled_rand > -1) { if (vec $string, $i, 1) { if ($i==$end+1) { # we ran off the end without getting a good number $found=0; last; } }else{ $fiddled_rand--; } $i++; } unless ($found) { $i=$start; while ($rand) { unless (vec $string, $i++, 1) { $rand--; } } } print "$i+"; vec($string, ($i-1), 1)=1; while (vec $string, $start, 1){$start++} while (vec $string, $end, 1){$end--} $number--; }