irandom_range

Returns a random integer between n1 and n2.

Syntax:

irandom_range(n1, n2);


Argument Description
n1 The low end of the range from which the random number will be selected.
n2 The high end of the range from which the random number will be selected.


Returns: Integer


Description

This function is similar to random_range() only with integer values as the input. So irandom_range(10, 35) will return an integer between 10 and 35. As with the irandom() function, real numbers can be used, in which case they will be rounded down to the nearest integer EG: irandom_range(6.2,9.9) will give a value between 6 and 9.

NOTE: This function will return the same value every time the game is run afresh due to the fact that GameMaker: Studio generates the same initial random seed every time to make debugging code a far easier task. To avoid this behaviour use randomize at the start of your game.


Example:

score += irandom_range(500, 600);

This will add anywhere between 500 and 600, an integer value, to the total score.


Back: Real Number Functions
Next: random_set_seed
© Copyright YoYo Games Ltd. 2018 All Rights Reserved