Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

mt_srand(3) [php man page]

MT_SRAND(3)								 1							       MT_SRAND(3)

mt_srand - Seed the better random number generator

SYNOPSIS
void mt_srand ([int $seed]) DESCRIPTION
Seeds the random number generator with $seed or with a random value if no $seed is given. Note There is no need to seed the random number generator with srand(3) or mt_srand(3) as this is done automatically. PARAMETERS
o $seed - An optional seed value RETURN VALUES
No value is returned. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.2.1 | | | | | | | The Mersenne Twister implementation in PHP now | | | uses a new seeding algorithm by Richard Wagner. | | | Identical seeds no longer produce the same | | | sequence of values they did in previous versions. | | | This behavior is not expected to change again, | | | but it is considered unsafe to rely upon it none- | | | theless. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 mt_srand(3) example <?php // seed with microseconds function make_seed() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000); } mt_srand(make_seed()); $randval = mt_rand(); ?> SEE ALSO
mt_rand(3), mt_getrandmax(3), srand(3). PHP Documentation Group MT_SRAND(3)

Check Out this Related Man Page

MT_RAND(3)								 1								MT_RAND(3)

mt_rand - Generate a better random value

SYNOPSIS
int mt_rand (void ) DESCRIPTION
int mt_rand (int $min, int $max) Many random number generators of older libcs have dubious or unknown characteristics and are slow. By default, PHP uses the libc random number generator with the rand(3) function. The mt_rand(3) function is a drop-in replacement for this. It uses a random number generator with known characteristics using the Mersenne Twister, which will produce random numbers four times faster than what the average libc rand() provides. If called without the optional $min, $max arguments mt_rand(3) returns a pseudo-random value between 0 and mt_getrandmax(3). If you want a random number between 5 and 15 (inclusive), for example, use mt_rand(5, 15). Caution This function does not generate cryptographically secure values, and should not be used for cryptographic purposes. If you need a cryptographically secure value, consider using random_int(3), random_bytes(3), or openssl_random_pseudo_bytes(3) instead. PARAMETERS
o $min - Optional lowest value to be returned (default: 0) o $max - Optional highest value to be returned (default: mt_getrandmax(3)) RETURN VALUES
A random integer value between $min (or 0) and $max (or mt_getrandmax(3), inclusive), or FALSE if $max is less than $min. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.3.4 | | | | | | | Issues an E_WARNING and returns FALSE if $max < | | | $min. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 mt_rand(3) example <?php echo mt_rand() . " "; echo mt_rand() . " "; echo mt_rand(5, 15); ?> The above example will output something similar to: 1604716014 1478613278 6 NOTES
Caution The distribution of mt_rand(3) return values is biased towards even numbers on 64-bit builds of PHP when $max is beyond 2^32. This is because if $max is greater than the value returned by mt_getrandmax(3), the output of the random number generator must be scaled up. SEE ALSO
mt_srand(3), mt_getrandmax(3), random_int(3), random_bytes(3), openssl_random_pseudo_bytes(3), rand(3). PHP Documentation Group MT_RAND(3)
Man Page