Return a standard normally distributed random vector i.e values between
-1 and 1.

@param int $n
@throws \InvalidArgumentException
@return self
19329
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);
    }
1004568
protected static function random($blockSize = Cuid::NORMAL_BLOCK)
    {
        // Get random integer
        $modifier = pow(Cuid::BASE36, Cuid::NORMAL_BLOCK);
        $random = mt_rand() / mt_getrandmax();

        $random = $random * $modifier;

        // Convert integer to hash
        $hash = Cuid::pad(
            base_convert(
                $random,
                Cuid::DECIMAL,
                Cuid::BASE36
            ),
            Cuid::NORMAL_BLOCK
        );

        // Limit hash if small block required
        if ($blockSize == Cuid::SMALL_BLOCK) {
            $hash = substr($hash, -2);
        }

        return $hash;
    }
163748
public function negated() : BigDecimal
    {
        return new BigDecimal(Calculator::get()->neg($this->value), $this->scale);
    }
576537
public function randomSubsetWithReplacement(int $n) : self
    {
        if ($n < 1) {
            throw new InvalidArgumentException('Cannot generate a subset of'
                . " less than 1 sample, $n given.");
        }

        $max = $this->numRows() - 1;

        $subset = [];

        for ($i = 0; $i < $n; $i++) {
            $subset[] = $this->samples[rand(0, $max)];
        }

        return self::quick($subset);
    }
479368
public function negative()
    {
        if (!is_int($this->value) && !is_float($this->value)) {
            throw new InvalidIntOrFloatException($this->name, $this->value);
        } elseif ($this->value >= 0) {
            throw new NumberNotNegativeException($this->name, $this->value);
        }

        return $this;
    }
919008
public static function notPerfectPowers(int $n): array
    {
        $npp = [];

        if ($n <= 0) {
            return $npp;
        }

        $i = 2;
        while ($n > 0) {
            if (!Integer::isPerfectPower($i)) {
                $npp[] = $i;
                $n--;
            }
            $i++;
        }

        return $npp;
    }
89842
public static function invertBits($n){
		$bits = \floor(\log($n, 2)) + 1;
		$mask = (1 << $bits) - 1;
		return $n ^ $mask;
	}
707378
public function &random($m = null, $n = null, $a = RAND_MIN, $b = RAND_MAX)
    {
        if (is_int($m) && is_int($n) && is_numeric($a) && is_numeric($b)) {
            $R = new Matrix($m, $n);
 
            for ($i = 0; $i < $m; $i++) {
                for ($j = 0; $j < $n; $j++) {
                    $R->set($i, $j, mt_rand($a, $b));
                }
            }
 
            return $R;
        } else {
            trigger_error(ArgumentTypeException, ERROR);
        }
    }
1263713
public static function ints(int $min, int $max, int $n = 10) : array
    {
        if (($max - $min) < 0) {
            throw new InvalidArgumentException('Maximum cannot be'
                . ' less than minimum.');
        }

        if ($n < 1) {
            throw new InvalidArgumentException('Cannot generate less'
                . ' than 1 parameter.');
        }

        if ($n > ($max - $min + 1)) {
            throw new InvalidArgumentException('Cannot generate more'
                . ' unique integers than in range.');
        }

        $distribution = [];

        while (count($distribution) < $n) {
            $r = rand($min, $max);

            if (!in_array($r, $distribution)) {
                $distribution[] = $r;
            }
        }

        return $distribution;
    }
690885
public function write_long($n)
    {
        if (($n < 0) || ($n > 4294967295)) {
            throw new AMQPInvalidArgumentException('Long out of range: ' . $n);
        }

        //Numeric strings >PHP_INT_MAX on 32bit are casted to PHP_INT_MAX, damn PHP
        if (empty($this->is64bits) && is_string($n)) {
            $n = (float) $n;
        }
        $this->out .= pack('N', $n);

        return $this;
    }
752219
public function protectedPrepMontgomery($x, $n)
    {
        $lhs = new BigInteger();
        $lhs->value = array_merge($this->protectedArrayRepeat(0, count($n)), $x);
        $rhs = new BigInteger();
        $rhs->value = $n;
        list ($temp) = $lhs->divide($rhs);
        return $temp->value;
    }
766303
public static function createRandom($passes = 1) : self
    {
        for($i = 0; $i < $passes; $i++) {
            $sensor = new self(
                Random::randomFloat(-0.3, 0.3),
                Random::randomFloat(-0.2, 2.5),
                Random::randomFloat(-0.2, 5),
                Random::randomFloat(0.08, 0.20),
                Random::randomFloat(0.45, 0.62),
                Random::randomFloat(9, 12),
                Random::randomFloat(40, 50),
                Random::randomFloat(-3, 3),
                Random::randomFloat(-125, -85),
                0,
                0,
                0
            );
        }

        return $sensor;
    }
118838
public static function random(self $y): self
    {
        $zero = self::createFromDecimal(0);

        return self::createFromGMPResource(\gmp_random_range($zero->value, $y->value));
    }
696594
public static function num2alpha($n)
    {
        $n = $n - 1;
        $r = '';
        for ($i = 1; $n >= 0 && $i < 10; $i++) {
            $r = chr(0x41 + ($n % pow(26, $i) / pow(26, $i - 1))) . $r;
            $n -= pow(26, $i);
        }
        return $r;
    }
970338
private function fromZigZag($n)
    {
        if (PHP_INT_SIZE === 4) {
            $n = gmp_init($n, 10);
        }
        $result = ($n >> 1) ^ -($n & 1);
        if (PHP_INT_SIZE === 4) {
            $result = gmp_strval($result, 10);
        }

        return $result;
    }
1331588
public function skip($n)
    {
        return new Enumerator(
            function () use($n) {
                foreach ($this->each() as $v) {
                    if (0 < $n) {
                        -- $n;
                    } else {
                        yield $v;
                    }
                }
            }
        );
    }
397376
public function topN(int $n): self
    {
        if (!$this->isSorted) {
            usort($this->list, [$this, 'compare']);
            $this->isSorted = true;
        }

        $topNList = new self();
        $topNList->insertFromArray(array_slice($this->list, -$n, $n));

        return $topNList;
    }