+use Maasha::Biopieces;
+use Maasha::Filesys;
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, $tmp_dir, $tmp_file, $fh_out, $fh_in, $count, $i, %rand_hash, $rand, $max );
+
+$options = Maasha::Biopieces::parse_options(
+ [
+ { long => 'num', short => 'n', type => 'uint', mandatory => 'no', default => 10, allowed => undef, disallowed => 0 },
+ ]
+);
+
+$in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
+$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
+
+$tmp_dir = Maasha::Biopieces::get_tmpdir();
+$tmp_file = "$tmp_dir/random_records.tmp";
+
+$fh_out = Maasha::Filesys::file_write_open( $tmp_file );
+
+$count = 0;
+
+while ( $record = Maasha::Biopieces::get_record( $in ) )
+{
+ Maasha::Biopieces::put_record( $record, $fh_out );
+
+ $count++;
+}
+
+close $fh_out;
+
+$max = 0;
+$i = 0;
+
+Maasha::Common::error( qq(Requested random records > records in stream) ) if $options->{ "num" } > $count;
+
+while ( $i < $options->{ "num" } )
+{
+ $rand = int( rand( $count ) );
+
+ if ( not exists $rand_hash{ $rand } )
+ {
+ $rand_hash{ $rand } = 1;
+
+ $max = $rand if $rand > $max;
+
+ $i++;
+ }
+}
+
+$fh_in = Maasha::Filesys::file_read_open( $tmp_file );
+
+$count = 0;
+
+while ( $record = Maasha::Biopieces::get_record( $fh_in ) )
+{
+ Maasha::Biopieces::put_record( $record, $out ) if exists $rand_hash{ $count };
+
+ last if $count == $max;
+
+ $count++;
+}
+
+close $fh_in;
+
+unlink $tmp_file;
+Maasha::Filesys::dir_remove( $tmp_dir );
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+BEGIN
+{
+ $run_time_beg = Maasha::Biopieces::run_time();
+
+ Maasha::Biopieces::log_biopiece();
+}
+
+
+END
+{
+ Maasha::Biopieces::close_stream( $in );
+ Maasha::Biopieces::close_stream( $out );
+
+ $run_time_end = Maasha::Biopieces::run_time();
+
+ Maasha::Biopieces::run_time_print( $run_time_beg, $run_time_end, $options );
+}
+
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+__END__