Stem-and-leaf plot/Data generator: Difference between revisions

A note about variable names.
(No newlines.)
(A note about variable names.)
 
(2 intermediate revisions by 2 users not shown)
Line 1:
Written to generate data sets for the [[Stem-and-leaf plot]] task. Statistics aren't my field or area of significant expertise, so some of the variable names might represent my homebrew understanding more than official terminology. --[[User:Short Circuit|Michael Mol]] 19:34, 14 December 2009 (UTC)
 
<lang perl>#!/usr/bin/perl
Line 12:
return @a;}
 
# The greater your pointcount to your width, the more pronouncedsparse your "hump" will beresult.
sub genhump
{
my ($offset, $width, $pointcount, $slope) = shift@_;
 
my $width = shift;
my $pointcountdiecount = shift$slope;
my $range = $width / $diecount;
 
my @ret;
foreach (1 .. $pointcount)
push @ret, (int(rand($width)+$offset))
{
while(($pointcount--) > 0);
my $point = $offset;
foreach (1 .. $diecount)
{
$point += rand($range * 10000) / 10000;
}
 
push @ret, (int(rand($width)+$offset)point);
}
 
return @ret;
}
 
my @list = (&genhump(8, 3, 5, 3);,
push @list, &genhump(012, 3, 105, 306));
 
push @list, &genhump(0, 10, 30);
push @list, &genhump(15, 10, 30);
 
my @shuffled = &shuffle(@list);
 
print "$_ @shuffled\n";</lang>
foreach ( @shuffled );
</lang>