Stem-and-leaf plot/Data generator
Written to generate data sets for the Stem-and-leaf plot task.
<lang perl>#!/usr/bin/perl use strict;
- The shuffle is taken from http://rosettacode.org/wiki/Knuth_shuffle
sub shuffle
{my @a = @_; foreach my $n (1 .. $#a) {my $k = int rand $n + 1; $k == $n or @a[$k, $n] = @a[$n, $k];} return @a;}
- The greater your pointcount to your width, the more pronounced your "hump" will be.
sub genhump { my $offset = shift; my $width = shift; my $pointcount = shift;
my @ret; push @ret, (int(rand($width)+$offset)) while(($pointcount--) > 0);
return @ret; }
my @list = ();
push @list, &genhump(0, 10, 30); push @list, &genhump(15, 10, 30);
my @shuffled = &shuffle(@list);
print "$_ " foreach ( @shuffled ); </lang>