babloo,
Ok - not knowing the reason you are supposed to do this without a module I didn't spend a lot of time trying to come up with a scientific solution. I did find that the following code did work surprisingly well for the requirements you specified:
#!/usr/bin/perl -w use strict; my $desired_mean = 250; my $desired_deviation = 20; my $total = 1000; my @numbers; gen_numbers(\@numbers, $desired_mean, $desired_deviation, $total); sub gen_numbers { my ($array_ref, $mean, $deviation, $total) = @_; my $offset = $deviation * 1.75; my $low = $mean - $offset; my $high = $mean + $offset; for (0 .. $total) { my $number; while (1) { $number = int(rand($high)) + 1; last if ($number >= $low && $number <= $high); } push @{$array_ref} , $number } } my $sum; $sum += $_ for @numbers; my $mean = $sum / $total; my $scratch; for (@numbers) { $scratch += (($_ - $mean) * ($_ - $mean)); } my $standard_deviation = sqrt($scratch / ($total - 1)); print "Desired Mean: $desired_mean\n"; print "Mean: $mean\n"; print "\n"; print "Desired Standard Deviation: $desired_deviation\n"; print "Standard Deviation: $standard_deviation\n"; __END__ Desired Mean: 250 Mean: 250.06707 Desired Standard Deviation: 20 Standard Deviation: 19.9571308028178

I doubt seriously it will work for anything other than 20 for a standard deviation since I used the fact that 3 standard deviations from the mean accounts for 99.7% in a normal distribution. I then fudge factored the remaining .3%.

Cheers - L~R


In reply to Re: how can i generate random numbers with predefined mean and standard deviation by Limbic~Region
in thread how can i generate random numbers with predefined mean and standard deviation by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.