cmr72 has asked for the wisdom of the Perl Monks concerning the following question:
Random number generator:
Histogram creator:#!/usr/bin/perl -w use strict ; my $samplesize = $ARGV[0] ; my $max = $ARGV[1] ; chomp(my $prog = `basename $0`) ; if ($#ARGV < 1) { print "\nUsage: ./randomnumber.pl <samplesize> <max num>\n" ; exit ; } for (my $i = 0; $i<$samplesize; $i++) { my $range = $max ; my $random_number = int(rand($range)) - $max/2; print "$random_number \n"; }
So if there are values -1, -1.5, -2, 2, 1, 0, 1, I would hope to see the following (if the bin range was between -2:2)#!/usr/bin/perl -w use strict ; my %bin ; my %size; my %value ; my $max = 0 ; my $min = 0 ; my $count ; while ( <STDIN> ) { my @line= split ; my $element = $line[0] ; $value{$element}++ ; } foreach my $i (sort {$a<=>$b} keys %value) { if ($i > $max) { $max = $i ; } if ($i < $min) { $min = $i ; } }
(-2) 3
(0) 1
(2) 3
Or something like that... Thanks in advance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help with Histograms
by toolic (Bishop) on Aug 29, 2012 at 00:37 UTC | |
|
Re: Help with Histograms
by philiprbrenan (Monk) on Aug 29, 2012 at 00:59 UTC | |
|
Re: Help with Histograms
by pvaldes (Chaplain) on Aug 29, 2012 at 15:43 UTC | |
|
Re: Help with Histograms
by cmr72 (Initiate) on Aug 29, 2012 at 20:00 UTC |