How do I implement Mersenne Twister into construct 3?

0 favourites
  • 7 posts
From the Asset Store
Casino? money? who knows? but the target is the same!
  • How do I implement Mersenne Twister into construct 3? I tried to do it using JavaScript but I don't think its possible in C3? Any advice would be great. I just want to generate random numbers.

  • I would check out advanced random plugin first since that will be easier to use.

    That being said, I just put this JS into a script file into C3 and it worked, is there something missing there?

    gist.github.com/banksean/300494

    I called it with this script in an event and checked the console and saw some results:

    + System: On start of layout
    -> Run JavaScript: var m = new MersenneTwister();
     var randomNumber = m.random();
     console.log(randomNumber)
     randomNumber = m.random();
     console.log(randomNumber)
     randomNumber = m.random();
     console.log(randomNumber)
     randomNumber = m.random();
     console.log(randomNumber)
     randomNumber = m.random();
     console.log(randomNumber)
     randomNumber = m.random();
     console.log(randomNumber)
     randomNumber = m.random();
     console.log(randomNumber)
     randomNumber = m.random();
     console.log(randomNumber)
    
    [C3 runtime] Hosted in worker, rendering with WebGL 2 [AMD Radeon Pro 580 OpenGL Engine] (standard compositing)
    scriptsInEvents.js?id=jzqsfa9isho:10 0.3431817612145096
    scriptsInEvents.js?id=jzqsfa9isho:12 0.5235268464311957
    scriptsInEvents.js?id=jzqsfa9isho:14 0.8710040617734194
    scriptsInEvents.js?id=jzqsfa9isho:16 0.6369211783166975
    scriptsInEvents.js?id=jzqsfa9isho:18 0.3085083137266338
    scriptsInEvents.js?id=jzqsfa9isho:20 0.5256941944826394
    scriptsInEvents.js?id=jzqsfa9isho:22 0.6346792092081159
    scriptsInEvents.js?id=jzqsfa9isho:24 0.6408087760210037
    
  • What's wrong with the standard PRNG used in C3?

    newt Nepeo explained it in this post:

    construct.net/en/forum/construct-3/how-do-i-8/implement-advanced-random-146115

  • Not a thing, unless you need a seed, or complex noise.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • System expressions like choose(...values) and random(min, max) use the JavaScript Math.random() method. Which tends to be fairly high quality ( certainly better the MST ) but doesn't allow for seeding. It's down the browser vendor to what algorithm they use for it. I believe Chrome uses an xorshift variant.

    The Advanced Random plugin uses the xorshiro256* algorithm, in which we allow the developer to specify a seed ( although the default mode uses a random seed ). More advanced features of Advanced Random like perlin noise, permutation tables and cellular noise all that PRNG as a source. So are based off the seed. You can also set Advanced Random to replace the source of randomness which the System expressions use.

    newt what do you mean by complex noise? We have 2D and 3D variants of Improved Perlin, Billow, Ridged, Cellular and Voronoi noise. Perlin and it's derivatives utilise Fractional Brownian Motion as well. They are all derived from a seed.

    you should be able to create MersenneTwister using JavaScript if you want. I'm not that familiar with the algorithm but there is an implementation here. It's worth noting that it is quite complex and isn't considered "good" anymore. There's some passable simple PRNGs written in JS here. I'm not sure what the quality is like, but they will likely be "good enough".

  • That's what I meant. Something besides white noise, tv snow, etc.

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