Advanced Random question

0 favourites
  • 10 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • Im looking to seed the RNG so I can pull predictable random values when needed but the only way it looks like I can get at the values is to choose to seed the runtime and use Random? If the runtime is using the same RNG for it will break the sequence of numbers?

    Ideally what I need is something like "Seed <tag>" and have something like "Random <tag>" to pull from that stream of numbers. Or maybe instances of Advanced Random with its own Random action.

    Nepeo Am I missing something? :)

  • Im looking to seed the RNG so I can pull predictable random values when needed but the only way it looks like I can get at the values is to choose to seed the runtime and use Random?

    Are you referring to the "random" function from the system actions? If so, inside the Advanced Random plugin, there's a checkbox to replace the system random seed. So unchecking it will make the seed for advanced random and system random separate. If that is checked then both will be the same.

    Is that what you mean?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That would work and I can use Random to get system random, but how do I get numbers from Advanced Random?

  • There are several ways to get numbers out of Advanced Random. Here is the manual entry for it that explains everything it can do: There is also 2 examples on the C3 start page under "Advanced Examples" named "Noise textures" and "Procedural terrain generation".

    It all depends on what kind of random numbers you need. If you need to a simple random number between 2 numbers, then just use the random system expression (search for random).

    If you are looking for something more complicated then that, then the Advanced Random plugin can do 4 things.

    1) Generate organized noise (perlin noise for example)

    2) Generate a gradient (I don't many people use this)

    3) Probability table

    4) Permutation table

    A use case for organized noise is for generating landscapes or procedural textures.

    The gist of a Probability table is being able to easily do weighted probabilities. Like for loot drops, 3 items each have 30% to drop but 1 item is rare and has only 10% to drop.

    The gist of a Permutation table is being able to draw from a randomly shuffled sequence of numbers, like a deck of cards. That way the random numbers never repeat.

    Hope this helps. Sorry if you know all this already. It's kind of hard to understand exactly what you're asking.

  • I simply need an expression to pull a stream of predictable numbers from a seeded RNG. Something like AdvancedRandom.Random(). I could give noise a try.

    Edit: Noise isnt random enough but using a probability table looks like it could be a workaround. Thanks for your help Fib!

  • I'm not sure I quite understand what you were want, but hopefully I can help a little.

    By default the system random expressions use the browsers inbuilt PRNG, which uses a random seed ( the seed is unknown to the consumer, and cannot be set ).

    The AdvancedRandom plugin has its own PRNG, separate to the browsers one. It uses this PRNG as a source of randomness for all its expressions. This PRNG has its seed set when your game starts. If the user specifies a seed in the object properties then it uses that, otherwise it will use the browser PRNG to generate a unique one. During runtime this seed can be read, and changed. It's also possible to generate new unique seeds from the browser PRNG using the RandomSeed expression.

    There's no direct way to get a value from the PRNG in Advanced Random. But as Fib says there is a check box in the Advanced Random properties which changes the PRNG that the system random expressions uses to be the one in Advanced Random. Allowing you access to those random expressions as well.

    So in summary, the PRNG is only predictable if you set the seed to be a predictable one and you can create a new unpredictable seed at any time.

  • Thanks for answering Nepeo.

    Using advanced random to override system random using a known seed guarantees the numbers it spits out will be predictable, but thats across the whole runtime, not as and when you might need them.

    For example: using advanced random to pre-generate levels will work. I want to generate levels in real-time, which looks like it will only work as long as I use a single probability table and dont override system random.

  • Advanced Random probability tables turned out to be quite convoluted. I ended up using this script alongside a couple of C3 functions, one to set the seed and another to get the next value:

    Its a little hacky since id prefer to keep everything as native as possible. Maybe Advanced Random could be updated in the future to allow it to be either instanced or have tags to allow for multiple RNGs along with an expression to simply pull the next number.

  • It's disappointing to discover Advanced Random will not allow me to pull simple seeded random numbers (0-1.0 for example) without overriding the system's random number generation. I am also trying to create a game with real-time level generation so I only want some of my random numbers to be tied to a specific seed.

    Is there any chance this plugin can be updated or does anyone else know of a decent workaround?

  • robit_studios You can simply generate a sequence of random numbers in advance and store it in an array. Say, generate 10K numbers. Then your "seed" will be an offset position, starting from which you'll read numbers from the array.

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