PHP.nl

rand

rand

Generate a random integer

int **rand**
int **rand** int $min int $max

If called without the optional , arguments returns a pseudo-random integer between 0 and . If you want a random number between 5 and 15 (inclusive), for example, use . min``max``rand``getrandmax``rand(5, 15)

Opmerking: > Prior to PHP 7.1.0, was only 32767 on some platforms (such as Windows). If you require a range larger than 32767, specifying and will allow you to create a range larger than this, or consider using instead. getrandmax``min``max``mt_rand

Opmerking: > As of PHP 7.1.0, uses the same random number generator as . To preserve backwards compatibility allows to be smaller than as opposed to returning false as .rand``mt_rand``rand``max``min``mt_rand

minThe lowest value to return (default: 0)

max The highest value to return (default: ) getrandmax

A pseudo random value between (or 0) and (or , inclusive). min``max``getrandmax

Voorbeeld: example

<?php
echo rand(), "\n";
echo rand(), "\n";

echo rand(5, 15), "\n";
?>
7771
22264
11

Waarschuwing: > range must be within the range . i.e. abs( - ) <= . Otherwise, may return poor-quality random numbers. min``max``getrandmax``max``min``getrandmax``rand

srand``getrandmax``mt_rand``random_int``random_bytes