Implement Advanced random

  • Hello construct 3 community!

    I'm trying to implement advanced random for my game. In order to improve the random aspect of my game.

    I read the documentation here: construct.net/en/make-games/manuals/construct-3/plugin-reference/advanced-random

    However, I am a little confused. Is it sufficient to use the random function of construct 3. And at the same time to have included the module "AdvancedRandom" and check the box "Replace system random"?

    And what about the seed ? The seed must be defined by us or can we leave the space "blank"? Can the seed be generated randomly, if so, on each call or only at the beginning of the game? And how the seed can be random knowing that it determines the random (the snake bites its tail)

  • Well, a simple test shows that if you leave the seed field empty in plugin properties, it will not be used. (basically no different from the system random)

    If you enter seed value, all random functions will use this seed and generate the same numbers every time you run your game.

    However, if you need to set the seed to a random value later in the game with events, don't set it to "", set it to some time expression (tickcount for example, or unixtime)

  • Thank you :)

    But I didn't find this function "Update seed" in the advanced random module.

  • Add action -> Advanced random -> Update seed

  • Including the plugin into your game, and selecting the "replace system random" tickbox will change all random based system expressions to use the AdvancedRandom's Psuedo random number enerator (PRNG) instead of the browser's PRNG. The advantage to this being that the browser doesn't not offer a way to read/modify the seed of it's PRNG, but AdvancedRandom does. Knowing the seed allows use to produce a repeatable sequence of seemingly random values, useful if players want to share this seed with others to get the same results. Or if you want to cherry pick one or more sequences that suits your game ( a common way of improving the quality of procedural generation ).

    If the "seed" property of the plugin is left blank, which it is by default, then it will use the browser PRNG to create a 10 letter seed and initialise itself. You can modify the seed at runtime using the "Set seed" action which accepts a string of any length. The "Seed" expression will return the current seed and the "RandomSeed" expression will return a new 10 letter seed generated using the browser PRNG.

    If you want to you can call the "Set seed" action with the "CurrentSeed" expression to reset the random number sequence to it's beginning.

  • Including the plugin into your game, and selecting the "replace system random" tickbox will change all random based system expressions to use the AdvancedRandom's Psuedo random number enerator (PRNG) instead of the browser's PRNG. The advantage to this being that the browser doesn't not offer a way to read/modify the seed of it's PRNG, but AdvancedRandom does. Knowing the seed allows use to produce a repeatable sequence of seemingly random values, useful if players want to share this seed with others to get the same results. Or if you want to cherry pick one or more sequences that suits your game ( a common way of improving the quality of procedural generation ).

    If the "seed" property of the plugin is left blank, which it is by default, then it will use the browser PRNG to create a 10 letter seed and initialise itself. You can modify the seed at runtime using the "Set seed" action which accepts a string of any length. The "Seed" expression will return the current seed and the "RandomSeed" expression will return a new 10 letter seed generated using the browser PRNG.

    If you want to you can call the "Set seed" action with the "CurrentSeed" expression to reset the random number sequence to it's beginning.

    Thank you for these details but does it negatively influence performance if I generate a random seed at every tick? Is it better to generate a random site before each random function?

    However, this is not clear to me. How can I create a random seed I can't find the function and "update seed" doesn't seem to accept "random". I didn't find "Set seed" function too...

    The random function (not from your plugin) really doesn't seem to work well but I have same result actually with your plugin and a seed that I tested. It often returns 1 or 2 when I put random(1,2) when there are millions of possible combinations....

  • TILK Why do you need to generate a new random seed on every tick or after every random function?

    Seeded random in game development is most commonly used for procedural level generation. For example, if you generate levels in your game randomly, but you want levels to be exactly the same for all players, you use the seed.

    Generating a new seed on every tick doesn't make sense. Just don't use it. Or if you are already using it, update the seed once to AdvancedRandom.RandomSeed or to unixtime and forget about it. Here is an example:

  • I need good and realistic random for my dice. I wanted to change the seed every time I rolled the dice.

  • And why do you need AdvancedRandom or seeded random for that?

    floor(random(1,7)) or choose(1,2,3,4,5,6) will give you a perfectly random result every time you roll the dice.

  • As dop2000 says changing the seed every tick won't make your dice rolls any more random.

    The operation to update the seed is relatively slow, as it does additional setup for the Perlin noise generation.

    I'm not sure what your intention for the dice is but the AdvancedNoise plugin also includes the ability to generate a list of non repeating numbers, like shuffling a deck of unique cards.

  • Ok thanks so without your plugin (advanced random) how random numbers (by default in the engine) are generate with random() function ?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Never do something you think is clever in order to make a random "more random". All Random number generators are designed with a single seed value supplied at initialization (nanoseconds since 1900 for example) and then numbers taken one after another.

    I've had some bonkers bugs because people have generated multiple random number generators.

  • TILK the default random number generator uses the JavaScript Math.random.

    Returns a Number value with positive sign, greater than or equal to 0 but less than 1, chosen randomly or pseudo randomly with approximately uniform distribution over that range, using an implementation-dependent algorithm or strategy. This function takes no arguments.

    Each Math.random function created for distinct code Realms must produce a distinct sequence of values from successive calls.

    The actual implementation of this method differs from browser to browser. I believe Chrome uses the xorshift128+ algorithm for this. All psuedo random number generators require a seed, the difference here being that the JS Math.random method doesn't allow you to choose a seed. It is chosen by the browser using a source of randomness provided by the operating system.

    We use xorshiro256** for our random number generator, which is of the same family as xorshift128+. I would expect the quality levels to be fairly similar to the Chrome one. I will note neither of these methods are considered "cryptographically secure" but that doesn't mean the quality is poorer. It just means that you cannot use the output of the generator to derive other values in the sequence ( before or after the current output ). They can still exhibit excellent pseudo randomness and distribution.

  • nepO

    The quality of Math.random() is definitely lower quality than a crypto PRNG. Over many iterations you'll be able to spot that certain values are more likely than others. A perfect RNG would have equal chance of any number being generated.

    That being said, both are easily random enough for emulating some dice rolls (unless you're emulating trillions of dice rolls).

  • As I said the base requirements of a cryto PRNG do not require it to exhibit a better quality than a standard PRNG. There's many different qualities exhibited by different PRNG algorithms, and being cryptographically secure does not make one "the best". There are likely some which appear better, but also some which appear worse.

    Don't use cryptographic PRNGs in games. They are much slower, and will not exhibit any improvements for your players over a good quality standard PRNG. Even with a bad quality one players are unlikely to notice any difference.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)