random_range


描述

This function returns a random number between the specified range, and this return value does not need to be an integer. For example, random_range(20,50) will return a random number from 20 to 50, but the value may be a real number like 38,65265. Real numbers can also be used as input arguments.

注意:每次游戏重新运行时,此函数将返回相同的值,因为GameMaker Studio 2每次生成相同的初始随机种子,使调试代码变得更容易。要避免这种行为,请在游戏开始时使用随机化


语法:

random_range(n1, n2);


参数 描述
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:

实数


例如:

score += random_range(500, 600);

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