Hi TNX bro i have a new code that calculate the mean of random number and then calculate the variance , so make gaussian function

#Hi First practice for PR class use warnings ; use strict ; use GD::Graph::linespoints ; #use DBI ; #use utf8 ; #use Encode ; #my $sfile = '/root/source.txt' ; print 'First Number > ' ; chomp(my $A = <STDIN>) ; print 'Second Number > ' ; chomp(my $B = <STDIN>) ; #my @range = ($A..$B) ; #my $rndn = $range[int (rand(@range))] ; my @points = () ; my $counter = 0 ; while ($counter <= 999) { my $rndn = $A + (int rand($B - $A + 1)); push (@points,$rndn) ; $counter++ ; } #Calculate the Mean and Variance my $running_sum = 0; my $meansum ; my $vari ; my $element1 ; my $element2 ; foreach $element1 (@points) { $meansum += $element1; } my $mean = $meansum/1000 ; print "MEAN = $mean" , "\n" ; foreach $element2 (@points) { $vari += (($meansum - $element2)^2) ; } my $variance = ($vari/1000) ; print "Variance = $variance" , "\n" ; print 'Second Number > ' ; chomp(my $xi = <STDIN>) ; my $Gs1 = (1/sqrt(2*3.14*$variance)) ; my $Gs2 = 2.718^(-(($xi - $mean)^2)/(2*$variance)) ; my $Go = $Gs1 * $Gs2 ; print "$Gs1" , "\n" ; print "$Gs2" , "\n" ; print "$Go" , "\n" ; my $graph = new GD::Graph::linespoints(2000 , 2000) ; $graph->set( x_label => 'Points' , x_label_skip => 1 , y_label => 'Number' , y_label_skip => 1 , title => 'Time Vs Fee') or warn $graph->error ; $graph->plot(\@points); open OUT,'>','FirstPracticeTest.jpeg' or die "$!"; binmode OUT; print OUT $graph->gd->jpeg;

In reply to Re^4: Make random numbers by GHMON
in thread Make random numbers by GHMON

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.