This very useful function only returns integers (whole numbers). So, for example, to get a random number from 0 to 9 you can use

irandom(9)and it will return a number from 0 to 9inclusive. Note that floats can also be used but the upper value after the point will be excluded, soirandom(9.7)will return a value from 0 to 9 only. The function has an upper bound of $7fffffffffffffffLL, so care should be taken if using very large numbers.NOTE:This function will return the same value every time the game is run afresh due to the fact that GameMaker Studio 2 generates the same initial random seed every time to make debugging code a far easier task. 要避免这种行为，请在游戏开始时使用随机化。

irandom(n);

参数 | 描述 |
---|---|

n | The upper range from which the random number will be selected. |

整数

if irandom(9) = 1

{

score += 100;

}

This will produce a one in ten (since 0 is included) chance of adding 100 to the score.