Random number generator with normal distribution

Registered by Michael-Olaf

Implementation of a random number generator with normal distribution. Input paramters are: minimum and maximum.

Blueprint information

Status:
Started
Approver:
Michael-Olaf
Priority:
Medium
Drafter:
Michael-Olaf
Direction:
Approved
Assignee:
Michael-Olaf
Definition:
Approved
Series goal:
Accepted for trunk
Implementation:
Started
Milestone target:
milestone icon 2.0
Started by
Michael-Olaf

Related branches

Sprints

Whiteboard

Code for a normal distribution:

private static function gauss($min,$max){
     $x1 = 0;
     $x2 = 0;
     $w = 0;
     $y1 = 0;
     $y2 = 0;
     $deviation = ($max-$min)/6;
     $median = ($max+$min)/2;

        do {
            $x1 = 2.0 * (rand()/getrandmax()) - 1.0;
            $x2 = 2.0 * (rand()/getrandmax()) - 1.0;
            $w = $x1 * $x1 + $x2 * $x2;
        } while ( $w >= 1.0 );

        $w = sqrt( (-2.0 * log( $w ) ) / $w );
        $y1 = $x1*$w;

        $y1 *= $deviation;
        $y1 += $median;

     return $y1;
}

(?)

Work Items

Dependency tree

* Blueprints in grey have been implemented.

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.