rand - chung-leong/qb GitHub Wiki

rand - Random number

int rand( int min, int max)

int rand(void)

rand() generates a pseudo-random number. If called without the optional min, max parameters, rand() returns an integer between the minimum and maximum possible value for the integer type. If you want a random number between 5 and 15 (inclusive), for example, use rand(5, 15).

Parameters:

min - The lowest value to return. It can be a scalar or an array.

max - The highest value to return. It can be a scalar or an array.

Return Values:

A pseudo-random number between min and max when the two parameters are provided. When they are not, the range is determined by the type of the variable to which the return value is assigned. If $a = rand() and $a is uint8, then the pseudo-number returned will be between 0 and 255. If the variable is int32 instead, the range becomes 2,147,483,648 to 2,147,483,647. If min or max is an array, then the return value is also an array, the size of which match the larger or min and max.

The return type and size of rand() is controlled by the context of how the return value is used. If you assign rand() to an array with four elements, four different pseudo-numbers will be returned.

Version

1.0 and above.