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:

: This function will return a random integer between 0 and`irandom(n)`

`n`

, with`n`

included. For example, if you want a random integer between 0 and 10:

`var randomNumber = irandom(10);`

: Similar to`irandom_range(min, max)`

`irandom(n)`

, but lets you specify both a minimum and a maximum integer value. So, for an integer between 5 and 15:

`var randomNumber = irandom_range(5, 15);`

: Returns a random floating-point number between 0 and`random(n)`

`n`

, not including`n`

itself. If you require a float between 0 and 5:

`var randomNumber = random(5);`

: Gives a random floating-point number in the range of`random_range(min, max)`

`min`

to`max`

. Unlike`irandom_range`

, both min and max can be non-integer values. To get a float between 2.5 and 7.5:

`var randomNumber = random_range(2.5, 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)`

or `randomize()`

.

: Sets the seed for random number generation to a specific value.`random_set_seed(seed)`

`random_set_seed(12345); // Replace 12345 with your chosen seed number`

: Sets the seed to a random value based on the current time.`randomize()`

`randomize();`

Using `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.

- The random functions in GameMaker are deterministic, meaning they will produce the same sequence of numbers for a given seed.
- Always remember to use
`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.

- Can You Use C# in Unreal Engine?
- What Games Use Unreal Engine 5?
- Is Unreal Engine Open Source?
- What is Unreal Engine?
- Can Unreal Engine make 2D games?
- Does Unreal Engine Use C++?
- Does Unreal Engine Use Python?
- What Language Does Unreal Engine Use?
- Does Unreal Engine Use JavaScript?
- Does Unreal Engine work on Linux?
- How Do I Uninstall Unreal Engine 5?
- Is Blender or Unreal Engine Better?

Start building today

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.