GameMaker Studio offers several functions to generate random numbers, which can be used for a variety of purposes such as randomizing game events, generating procedural content, or just picking a random value within a specific range. Here's how you can use these functions:
irandom(n): This function will return a random integer between 0 and
n included. For example, if you want a random integer between 0 and 10:
irandom_range(min, max): Similar to
irandom(n), but lets you specify both a minimum and a maximum integer value. So, for an integer between 5 and 15:
random(n): Returns a random floating-point number between 0 and
n, not including
n itself. If you require a float between 0 and 5:
random_range(min, max): Gives a random floating-point number in the range of
irandom_range, both min and max can be non-integer values. To get a float between 2.5 and 7.5:
If you want to ensure that the same sequence of random numbers is generated each time your game runs, you need to set the seed using
random_set_seed(seed): Sets the seed for random number generation to a specific value.
randomize(): Sets the seed to a random value based on the current time.
randomize() at the start of your game is a good way to make sure that the random numbers are less predictable and different every time you run your game.
randomize() at the start of the game if you want unique random sequences per game session, otherwise, the sequence will repeat every time you run the game if the seed stays the same.
These are the basics of using random numbers in GameMaker. Depending on what you're trying to achieve, these functions can be incredibly powerful tools in adding unpredictability and variation to your games.