Stem-and-leaf plot/Data generator: Difference between revisions
Content added Content deleted
(No newlines.) |
(A note about variable names.) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
Written to generate data sets for the [[Stem-and-leaf plot]] task. |
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 |
<lang perl>#!/usr/bin/perl |
||
Line 12: | Line 12: | ||
return @a;} |
return @a;} |
||
# The greater your pointcount to your width, the more |
# The greater your pointcount to your width, the more sparse your result. |
||
sub genhump |
sub genhump |
||
{ |
{ |
||
my $offset = |
my ($offset, $width, $pointcount, $slope) = @_; |
||
my $width = shift; |
|||
my $ |
my $diecount = $slope; |
||
my $range = $width / $diecount; |
|||
my @ret; |
my @ret; |
||
foreach (1 .. $pointcount) |
|||
⚫ | |||
{ |
|||
while(($pointcount--) > 0); |
|||
my $point = $offset; |
|||
foreach (1 .. $diecount) |
|||
{ |
|||
$point += rand($range * 10000) / 10000; |
|||
} |
|||
⚫ | |||
} |
|||
return @ret; |
return @ret; |
||
} |
} |
||
my @list = () |
my @list = (&genhump(8, 3, 5, 3), |
||
⚫ | |||
⚫ | |||
push @list, &genhump(15, 10, 30); |
|||
my @shuffled = &shuffle(@list); |
my @shuffled = &shuffle(@list); |
||
print " |
print "@shuffled\n";</lang> |
||
foreach ( @shuffled ); |
|||
</lang> |
Latest revision as of 19:34, 14 December 2009
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. --Michael Mol 19:34, 14 December 2009 (UTC)
<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 sparse your result.
sub genhump { my ($offset, $width, $pointcount, $slope) = @_;
my $diecount = $slope; my $range = $width / $diecount;
my @ret; foreach (1 .. $pointcount) { my $point = $offset; foreach (1 .. $diecount) { $point += rand($range * 10000) / 10000; }
push @ret, int($point); }
return @ret; }
my @list = (&genhump(8, 3, 5, 3),
&genhump(12, 3, 5, 6));
my @shuffled = &shuffle(@list);
print "@shuffled\n";</lang>