open.mp | random
  • Home
  • FAQ
  • Forum
  • Servers
  • Docs
  • Blog
  • Login
  • Englishاللغة العربيةar-TNবাংলাbosanski jezikDeutschΕλληνικάEspañoleestiفارسیFrançaisHrvatskimagyarBahasa IndonesiaItaliano日本語ქართულიlietuvių kalbaNederlandsNorskjęzyk polskiPortuguêsRomânăРусскийslovenski jezikсрпски језикไทยWikang TagalogTürkçeУкраїнськаاردوTiếng Việt简体中文繁體中文
warning Not Translated

This page has not been translated into the language that your browser requested. The English content is being shown as a fallback.

If you want to contribute a translation for this page then please click here.

random

warning

This $function starts with a lowercase letter.

Description

Get a pseudo-random number.

NameDescription
maxThe range of values (from 0 to this value minus one) that can be returned.

Returns

A random number ranging from 0 to max-1.

Examples

new value = random(5);

// 'value' might be 0, 1, 2, 3 or 4. 5 possible values.
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 rand = random(sizeof(RandomSpawn));

    // SetPlayerPos to the random spawn data
    SetPlayerPos(playerid, RandomSpawn[rand][0], RandomSpawn[rand][1],RandomSpawn[rand][2]);

    // SetPlayerFacingAngle to the random facing angle data
    SetPlayerFacingAngle(playerid, RandomSpawn[rand][3]);
    return 1;
}

Notes

tip

Using a value smaller than 1 gives weird values.

Related Functions

Community

  • Discord
  • Instagram
  • Twitter
  • Twitch
  • YouTube
  • Facebook
  • VK

More

  • SA-MP
  • Blog
  • GitHub