I've recently run into a weird problem. When I create instances through with(instance_create){ ... }, I can always randomize their variables individually (inside {...}). However, when I try running


inside their object (in one of the events), they are all synced. Please tell me this isn't a major Game Maker flaw and, most importantly, how do I fix this. Thank you!


1 Answer 1


There seems to be little information on the subject... this is what I gather:

  • Game Maker provides a single global random
  • Game Maker remembers the set random seed
  • randomize will set a "random" seed, is intended to be called only once

From the above it is very likely that calling randomize generates a seed based on the game or the machine, and calling it multiple times is indempotent.

To get over that problem you can use random_set_seed(val), but from where do you get the seed? If you try using random, that random will generate a value using the default seed, therfore it will always generate the same value.

Instead I suggest to use current_time for your seed. Under the assumption that calls to random_set_seed(current_time()) don't happen close enough in time, this will make sure it yields a different seed.

You can make it a bit more interesting if you wrap that in a function, and keep track of the number of times it has been called. Combining that with number with current_time would make sure that it sets a different seed every time it gets called even if the calls happen consecutively.

Note: using current_time may make your game suceptible to tampering by changing the system clock.

You could roll your own number generator, start by reading about Linear congruential generators

  • \$\begingroup\$ Thanks for the reply. Yes, looks like I have to do it the classic way. I'll make a function out of that (hope it's not heavy in terms of resources) \$\endgroup\$ Feb 5, 2017 at 8:39
  • \$\begingroup\$ I'm not sure what you're describing. The way it's supposed to be done is calling randomize() once (e.g. when the game starts) and then just calling random() when needed. No custom functions required. \$\endgroup\$
    – ABCRic
    Feb 9, 2017 at 8:04
  • \$\begingroup\$ @ABCRic In fact, I mentioned that randomize is inteded to be called only once. It would set a global seed for random. You can also set the seed by using random_set_seed, which is good if you want Replicability (for example for debugging or to replay gameplay by input playback), by setting the same seed again you would get the same results from random. But then adding another object that uses random will alter the behaviour of all other objects that use random even if the seed is the same. Apparently OP wants separate randoms... why? ask Yuriy Kotsar. \$\endgroup\$
    – Theraot
    Feb 9, 2017 at 8:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .