FEATURE REQUEST: random() function with custom seed, to produce a repeatable sequence

HopscotchHopscotch Member, PRO Posts: 2,782

it would be great if we could set a SEED for the random() function if needed, so as to always produce a predictable and repeatable sequence of random numbers.

Either have a setseed(seed) function, or an extra parameter thus: random(min,max,seed)

This would greatly enhance games where skill historically involves the ability to learn enemy patterns, e.g. SHMUPS or Platformers.

http://bugs.gamesalad.com/show_bug.cgi?id=1446

Comments

  • ArmellineArmelline Member, PRO Posts: 5,368

    I was going to suggest that just seeding a table with relevant numbers would achieve the same result, but this would actually be so much more helpful!

    I've been working on a shoot-em-up for someone, and there are enemies that travel a random pattern but are composed of multiple parts that follow each other. Something like this would make such enemies so much easier!

  • SocksSocks London, UK.Member Posts: 12,822

    @Armelline said:
    I was going to suggest that just seeding a table with relevant numbers would achieve the same result, but this would actually be so much more helpful!

    You could also jump into a particular place in Pi.

  • HopscotchHopscotch Member, PRO Posts: 2,782
    edited October 2015

    @Socks, although in GS it would only allow for a sequence of 14 single digits. If calculated. The alternative, giving you any number at the nth decimal place, would involve an impractically slow loop calculation.

    In most programming languages the pure random function always returns the same sequence by default. You need to seed it with something e.g. time, to get a different sequence every time.

  • ArmellineArmelline Member, PRO Posts: 5,368

    Lua lets you specify a seed, so hopefully this is one of those easier to do features.

  • SocksSocks London, UK.Member Posts: 12,822

    @Hopscotch said:
    Socks, although in GS it would only allow for a sequence of 14 single digits.

    How about choose an angle (let's say 218.37°) . . .

    Then add up the first 4 decimal place numbers from the sin of that angle until you reduce them to a single number . . .

    sin(218.37) = 0.6207 = 15 = 6

    List this number, add it to the original angle and repeat . . .

    sin(224.37) = 0.6992 = 26 = 8

    sin(232.37) = 0.7919 = 26 = 8

    sin(240.37) = 0.7919 = 25 = 7

    sin(247.37) = 0.9230 = 14 = 5

    sin(252.37) = 0.9530 = 17 = 6

    sin(258.37) = 0.9530 = 19 = 7

    . . . . etc, which would give you a series of numbers (8,8,7,5,6,7 . . . ) which would appear (for the purposes of gameplay certainly) random, whilst having a knowable start point (218.37).

    Something like that might work, you seed it with an angle and then extract a series of psuedo-random numbers, it would need to be constructed probably, my example is just a sketch (for example if the first 4 decimal places produced a 0, then the sequence would freeze at 0, but I'm sure you can factor stuff like that in with some simple logic).

Sign In or Register to comment.