Does Construct 3 Have Random Seeds?

0 favourites
  • 8 posts
From the Asset Store
Casino? money? who knows? but the target is the same!
  • I've spent the last several weeks working on a Facebook Instant word game which has levels that are generated algorithmically. Tonight I was going to seed the random number generator so everyone gets the same puzzle for each level -- this is important because of leaderboards, competition, etc. -- but there doesn't seem to be a way to do it.

    I assumed (yeah, I know the old saying) that this functionality would be built in, but it looks like I need a special plugin... and none have been ported to Construct 3 yet. Wow. I've solved a lot of problems to get where I am, but this is an issue I never even anticipated.

    I guess I could use a tool like Excel to randomly generate tens of thousands of levels (offline) and then save the values in a huge array. Any other suggestions?

  • Here is how it could work, but it's more a dirty hack.

    Im using mersenne-twister.js from here https://gist.github.com/banksean/300494 and use Browser.executeJS.

    It seems to work with a seed. I get every time the same value.

    Example:

    https://drive.google.com/uc?export=down ... d3rk87HXUs

  • There are many ways to create a "seeded" random. There are different advantages, disadvantages, and varying levels of complexity for different methods. Depending on your particular needs, you should pick the most suitable method. The general technique is called pseudo random number generation.

    https://gist.github.com/blixt/f17b47c62508be59987b

    https://www.geeksforgeeks.org/pseudo-ra ... ator-prng/

    https://en.wikipedia.org/wiki/Pseudoran ... _generator

    https://en.wikipedia.org/wiki/Middle-square_method

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • What sort of randomness do you need? Do you just a seeded random number or perlin style coherent noise?

  • [quote:fxfw6m52]What sort of randomness do you need? Do you just a seeded random number or perlin style coherent noise?

    Thanks for getting back to me, Nepeo!

    I don't think I need Perlin noise, I just want to make the random elements of my game deterministic, so all players get the same experience. I've found that this also helps with game testing.

    As I mentioned, my Facebook Instant game uses randomly generated word puzzles. If I could set a random seed then all players would get the same puzzle at each level of the game. (From 1 to infinity!) This is important because I want to have leaderboards and maybe some sort of challenge feature.

  • Yeah I totally get why you want seeded random. I've been working on a personal project ( webGL & JS ) where I needed coherent noise for infinite world generation, and have been planning to write a C3 plugin based on my experience.

    As far as I'm aware, we don't have any build in expressions to offer seeded random numbers. But it shouldn't be too hard to create a small plugin with MST or similar as an expression.

  • Here is a quick implementation of the first link I referenced above.

    https://www.dropbox.com/s/q4fcmtza4uqvyn8/prng.c3p?dl=0

    Each time the function is called it will return the next pseudo random integer between 1 to 2147483646 inclusive in series.

    To get a float between 0 and 1, use function.call("prng")-1/2147483646.

    To set a maximum value, modulo the result by whatever you want the maximum to be, OR multiply the float as above by the maximum.'

    Note that this is reliable across platforms as long as you stick with integers only. Once you use floats, rounding errors may occur.

    I tried to make a clean version in event 3 utilizing function.returnvalue, but it didn't work as expected. Can anyone else fix it? I ended up resorting to global variables to store the last returned value.

    With some minor modification, you should be able to pick out a specific number from the series by index by looping through the function x number of times from the seed value.

    The incrementing numbers represent the distribution of results.

  • That sounds amazing, oosyrag! When I get some time I'll check it out!

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