Přidat otázku mezi oblíbenéZasílat nové odpovědi e-mailem Game Maker -> Náhodnost

Description

random() generates a random real number between 0 and less than x. It is produced as a decimal fraction, so if you want a whole number (integer), you should use floor() or ceil() in combination with random(). floor() is used most often.


Examples

Simple Example

After the code below is executed, rnum} will contain a random real number between 0 and less than 5. Remember, this number will be a number with a decimal point and not an integer.

rnum = random(5)

50/50 Chance


A 50/50 chance can be simulated this way :

if (random(1) >= .5)
{
//something happens
}

Simulating Dice Rolls

Standard 6-sided dice and other polyhedral dice rolls can be simulated by simply using random() to generate a number between 1 and the maximum number of the die. Don't forget the + 1.

die = floor(random(6)) + 1

Reakce na odpověď

1 Zadajte svou přezdívku:
2 Napište svou odpověď:
3 Pokud chcete dostat ban, zadejte libovolný text:

Zpět do poradny