public static function gaussian(int $n) : self
    {
        if ($n < 1) {
            throw new InvalidArgumentException('The number of elements'
                . " must be greater than 0, $n given.");
        }

        $a = [];

        for ($i = 0; $i < $n; $i += 2) {
            $r1 = rand(0, PHP_INT_MAX) / PHP_INT_MAX;
            $r2 = rand(0, PHP_INT_MAX) / PHP_INT_MAX;
            
            $r = sqrt(-2. * log($r1));

            $a[] = $r * sin($r2 * self::TWO_PI);
            $a[] = $r * cos($r2 * self::TWO_PI);
        }

        if (count($a) > $n) {
            $a = array_slice($a, 0, $n);
        }

        return static::quick($a);
    }
public static function gaussian(int $n) : self
    {
        if ($n < 1) {
            throw new InvalidArgumentException('The number of elements'
                . " must be greater than 0, $n given.");
        }

        $a = [];

        for ($i = 0; $i < $n; $i += 2) {
            $r1 = rand(0, PHP_INT_MAX) / PHP_INT_MAX;
            $r2 = rand(0, PHP_INT_MAX) / PHP_INT_MAX;
            
            $r = sqrt(-2. * log($r1));

            $a[] = $r * sin($r2 * self::TWO_PI);
            $a[] = $r * cos($r2 * self::TWO_PI);
        }

        if (count($a) > $n) {
            $a = array_slice($a, 0, $n);
        }

        return static::quick($a);
    }
public static function gaussian ( int $ n ) : self { if ( $ n < 1 ) { throw new InvalidArgumentException ( 'The number of elements' . " must be greater than 0, $n given." ) ; } $ a = [ ] ; for ( $ i = 0 ; $ i < $ n ; $ i += 2 ) { $ r1 = rand ( 0 , PHP_INT_MAX ) / PHP_INT_MAX ; $ r2 = rand ( 0 , PHP_INT_MAX ) / PHP_INT_MAX ; $ r = sqrt ( - 2. * log ( $ r1 ) ) ; $ a [ ] = $ r * sin ( $ r2 * self :: TWO_PI ) ; $ a [ ] = $ r * cos ( $ r2 * self :: TWO_PI ) ; } if ( count ( $ a ) > $ n ) { $ a = array_slice ( $ a , 0 , $ n ) ; } return static :: quick ( $ a ) ; }
Return a standard normally distributed random vector i.e values between
-1 and 1.

@param int $n
@throws \InvalidArgumentException
@return self
Return a standard normally distributed random vector i . e values between - 1 and 1 .