Selects a number of randomly selected rows

@param   integer  $n  The number of rows to randomly select
@return  Rows
@since   2.1.13
518606
public function pickRandom($n)
	{
		$rows = $this->rows;

		shuffle($rows);
		$randomRows = array_slice($rows, 0, $n);
		$rowsObject = new self($randomRows);

		return $rowsObject;
	}
586014
public function resize($n)
    {
        return new self(function ($rng, $size) use ($n) {
            return $this->call($rng, $n);
        });
    }
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;
    }
482250
public static function random($array, $number = 1)
    {
        $result = [];
        $keys = array_rand($array, $number);
        foreach($keys as $key)
        {
            if(!isset($array[$key]))
            {
                break;
            }
            $result[$key] = $array[$key];
        }
        return $result;
    }
1036033
public static function get_records_select($select, $params = null, $sort = '', $fields = '*', $limitfrom = 0, $limitnum = 0) {
        global $DB;

        $records = $DB->get_records_select(static::TABLE, $select, $params, $sort, $fields, $limitfrom, $limitnum);

        // We return class instances.
        $instances = array();
        foreach ($records as $key => $record) {
            $instances[$key] = new static(0, $record);
        }

        return $instances;

    }
984458
public function allocateTo($n)
    {
        if (!is_int($n)) {
            throw new \InvalidArgumentException('Number of targets must be an integer');
        }

        if ($n <= 0) {
            throw new \InvalidArgumentException('Cannot allocate to none, target must be greater than zero');
        }

        return $this->allocate(array_fill(0, $n, 1));
    }
1331588
public function skip($n)
    {
        return new Enumerator(
            function () use($n) {
                foreach ($this->each() as $v) {
                    if (0 < $n) {
                        -- $n;
                    } else {
                        yield $v;
                    }
                }
            }
        );
    }
1128525
public function random($number = null)
    {
        if (is_null($number)) {
            return Arr::random($this->items);
        }

        return new static(Arr::random($this->items, $number));
    }
1076146
public function take($n)
    {
        return new Enumerator(
            function () use($n) {
                foreach ($this->each() as $k => $v) {
                    yield $k => $v;
                    if (-- $n < 1)
                        return;
                }
            }
        );
    }
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);
    }
1187033
public function skip($n)
    {
        $start = $this->currentPosition;

        $ret = @fseek($this->stream, $n, SEEK_CUR);
        if ($ret === -1) {
            return -1;
        }

        $this->currentPosition = ftell($this->stream);

        if ($start > $this->currentPosition) {
            $skipped = $start - $this->currentPosition;
        } else {
            $skipped = $this->currentPosition - $start;
        }

        return $skipped;
    }
861209
public function splice(int $offset, int $n) : self
    {
        $samples = array_splice($this->samples, $offset, $n);
        $labels = array_splice($this->labels, $offset, $n);

        return self::quick($samples, $labels);
    }
795489
public function randomize() : self
    {
        $order = range(0, $this->numRows() - 1);

        shuffle($order);

        array_multisort($order, $this->samples, $this->labels);

        return $this;
    }
379833
function take($numRows)
    {
        $this->getNodes()->limit = $numRows !== null ? new Limit($numRows) : null;
        return $this;
    }
922865
public function paginate($select, $resultSet = null)
    {
        $resultSet = $resultSet ?: $this->getResultSet();
        $adapter = new DbSelect($select, $this->getAdapter(), $resultSet);
        $paginator = new Paginator($adapter);

        $options = $this->getPaginatorOptions();

        if (isset($options['limit'])) {
            $paginator->setItemCountPerPage($options['limit']);
        }

        if (isset($options['page'])) {
            $paginator->setCurrentPageNumber($options['page']);
        }

        $paginator->setPageRange(5);

        return $paginator;
    }
436334
public function shuffle($seed = null)
    {
        $items = $this->items;

        if (is_null($seed)) {
            shuffle($items);
        } else {
            srand($seed);

            usort($items, function () {
                return rand(-1, 1);
            });
        }

        return new static($items);
    }
711058
public function createVertices($n)
    {
        $vertices = array();
        if (is_int($n) && $n >= 0) {
            for ($id = $this->getNextId(), $n += $id; $id < $n; ++$id) {
                $vertices[$id] = new Vertex($this, $id);
            }
        } elseif (is_array($n)) {
            // array given => check to make sure all given IDs are available (atomic operation)
            foreach ($n as $id) {
                if (!is_int($id) && !is_string($id)) {
                    throw new InvalidArgumentException('All Vertex IDs have to be of type integer or string');
                } elseif ($this->vertices->hasVertexId($id)) {
                    throw new OverflowException('Given array of Vertex IDs contains an ID that already exists. Given IDs must be unique');
                } elseif (isset($vertices[$id])) {
                    throw new InvalidArgumentException('Given array of Vertex IDs contain duplicate IDs. Given IDs must be unique');
                }

                // temporary marker to check for duplicate IDs in the array
                $vertices[$id] = false;
            }

            // actually create all requested vertices
            foreach ($n as $id) {
                $vertices[$id] = new Vertex($this, $id);
            }
        } else {
            throw new InvalidArgumentException('Invalid number of vertices given. Must be non-negative integer or an array of Vertex IDs');
        }

        return new Vertices($vertices);
    }