FEATURE REQUEST: random() function with custom seed, to produce a repeatable sequence
Hopscotch
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.
Comments
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!
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
You could also jump into a particular place in Pi.
@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.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
Lua lets you specify a seed, so hopefully this is one of those easier to do features.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
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).