I want to use a pseudorandom number generator that generates a seemingly random output from a seed number. Is there any way to do this using RPGM2k3's variable control commands? I want to stress that while the output is seemingly random, the same input number should have the same output every time.
2k/3 Anyone know how to make a Pseudorandom Number Generator?
RPG Maker 2000/2003 SupportRandomness is only what the player perceives as random.
Therefore tying a variable change function to... Anything without informing the player would create a sense of randomness.
You can base it off steps taken, buttons pushed, events activated, time, or a combination of all of the above.
As far as the seed, yes. I mean it's just a math function. Taking input apply a formula, give output. Take output feed it into the formula, rinse repeat.
You'd likely need to be more specific on what exactly it is you want to achieve.
Therefore tying a variable change function to... Anything without informing the player would create a sense of randomness.
You can base it off steps taken, buttons pushed, events activated, time, or a combination of all of the above.
As far as the seed, yes. I mean it's just a math function. Taking input apply a formula, give output. Take output feed it into the formula, rinse repeat.
You'd likely need to be more specific on what exactly it is you want to achieve.
What I'm trying to figure out is a formula where the outputs won't repeat themselves or have a noticeable pattern.
As a common, reliable, Pseudo-RNG algorithm, you have the Mersenne Twister.
Github is full of implementation of this algorithm in every language.
Github is full of implementation of this algorithm in every language.
I need an algorithm I make with RPG Maker 2003's variable manipulation commands.
You can implement some existing algorithm. Maybe a linear congruential generator with some modifications to ensure you stay in the RM2k3 variable range, you probably need some tweaks to avoid the `(a * state) % m` part which would otherwise leave the range, maybe adjusting the algorithm to work with two smaller parts in the calculation. I suggest you ask ChatGPT or some other AI for details here, make sure to state the limitations you are working with (variable range is -9999999 to +9999999 and you have +-*/% operations and conditions and no bitwise operations).
If you want to stick with the linear congruential generator idea, Wikipedia also has a good overview and links for possible settings (for example this paper)
If you mainly need some smaller values, you could use the example
output = x' = (x * 219) mod 32749
which works within the 9,999,999 limit without the need for emulation (x is your previous RNG output/seed value). It should cycle through 1-32748 in a messy but ultimately repeated order.
Late Edit: The starting value for x must not be 0 (or a multiple of 32749), other values are allowed.
To transform your random output into specific number ranges you can use
number = output mod (max - min + 1) + min
E.g. if you want a number between 30 and 100, you would transform your random output as
number = output mod 71 + 30
For bigger number ranges this will lead to smaller results being a bit more common. If that bothers you then you can reroll output values that are greater than
reroll threshold = 32749 / (max - min + 1) * (max - min + 1)
If you need bigger ranges than 3-4 digits you can also fuse multiple RNG rolls together.
Alternatively, if you also need a longer period, you can probably emulate bigger modulo operations, although at the cost of some performance. (Might be a bit more complex though)
If you mainly need some smaller values, you could use the example
output = x' = (x * 219) mod 32749
which works within the 9,999,999 limit without the need for emulation (x is your previous RNG output/seed value). It should cycle through 1-32748 in a messy but ultimately repeated order.
Late Edit: The starting value for x must not be 0 (or a multiple of 32749), other values are allowed.
To transform your random output into specific number ranges you can use
number = output mod (max - min + 1) + min
E.g. if you want a number between 30 and 100, you would transform your random output as
number = output mod 71 + 30
For bigger number ranges this will lead to smaller results being a bit more common. If that bothers you then you can reroll output values that are greater than
reroll threshold = 32749 / (max - min + 1) * (max - min + 1)
If you need bigger ranges than 3-4 digits you can also fuse multiple RNG rolls together.
Alternatively, if you also need a longer period, you can probably emulate bigger modulo operations, although at the cost of some performance. (Might be a bit more complex though)
Original thread: https://forums.rpgmakerweb.com/threads/anyone-know-how-to-make-a-pseudorandom-number-generator.181066/