Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

mt_rand(3) [php 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)

Check Out this Related Man Page

Math::RandomOrg(3pm)					User Contributed Perl Documentation				      Math::RandomOrg(3pm)

NAME
Math::RandomOrg - Retrieve random numbers and data from random.org. SYNOPSIS
use Math::RandomOrg qw(randnum randbyte); my $number = randnum(0, 10); my $octet = randbyte(1); DESCRIPTION
Math::RandomOrg provides functions for retrieving random data from the random.org server. Data may be retrieved in an integer or byte- stream format using the "randnum" and "randbyte" functions respectively. REQUIRES
Carp Exporter Math::BigInt LWP::Simple EXPORT
None by default. You may request the following symbols be exported: * randnum * randbyte FUNCTIONS
"checkbuf()" This routine takes no parameters and simply returns a single value (e.g., "28%") telling you how full the buffer is. At 100%, the buf- fer is full and you are free to hit it with automated clients. At 0%, the buffer is empty and requests will hang. When less than 100%, the buffer is being filled continually, but doing so takes time. I advise people with automated clients to check the buffer level every once in a while and only issue requests when the buffer level is 20% or higher. "randnum ( $min, $max )" Return an integer (specifically a Math::BigInt object) between the bounds [ $min, $max ] (inclusive). By default, $max and $min are positive and negative 1e9, respectively. These default values represent random.org's current extrema for the bounds of the randnum function. Therefore, $min and $max may not exceed the default values. "randbyte ( $length )" Returns an octet-string of specified length (defaults to one byte), which contains random bytes. $length may not exceed 16,384, as this is the maximum number of bytes retrievable from the random.org server in one request, and making multiple requests for an unbounded amount of data would unfairly tax the random.org server. If you need large amounts of random data, you may wish to try the Math::TrulyRandom module. "randseq ( $min, $max )" The randseq script returns a randomized sequence of numbers. This corresponds to dropping a number of lottery tickets into a hat and drawing them out in random order. Hence, each number in a randomized sequence occurs exactly once. Example: "randseq(1, 10)" will return the numbers between 1 and 10 (both inclusive) in a random order. BUGS
None known. SEE ALSO
* Math::TrulyRandom * rand COPYRIGHT
Copyright (c) 2001-2006 Gregory Todd Williams. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. AUTHOR
Gregory Todd Williams "<gwilliams@cpan.org>" perl v5.8.8 2008-03-09 Math::RandomOrg(3pm)
Man Page