Random

From SA-MP Wiki

Jump to: navigation, search

Random


Get a pseudo-random number, which will be number different possibilities starting with 0, ending with the number one smaller than number.
Parameters:
(max)
maxThe maximum number for the random sequence.
ReturnsA random number between 0 and max.

Function Example

new iRandomNumber = random(25); // Generates a number between 0 and 24

Usage Example

This usage example is based on a random spawn, though it can easily be modified.
new Float:RandomSpawn[][4] =
 {
  // Positions, (X, Y, Z and Facing Angle)
    {-2796.9854, 1224.8180, 20.5429, 192.0335},
    {-2454.2170, 503.8759, 30.0790, 267.2932},
    {-2669.7322, -6.0874, 6.1328, 89.8853}
 }
public OnPlayerSpawn(playerid)
{
    new iRandom = random(sizeof(RandomSpawn));
  // SetPlayerPos to the random spawn information
    SetPlayerPos(playerid, RandomSpawn[iRandom][0], RandomSpawn[iRandom][1],RandomSpawn[iRandom][2]);
//    SetPlayerFacingAngle to the random facing angle information
    SetPlayerFacingAngle(playerid, RandomSpawn[iRandom][3]);
    return 1;
}