Could anyone give me a hint on how to generate “smooth” random numbers?
Here’s what I mean by smooth:
The random numbers shall be used in a game, e.g. for wind direction and strength (does anyone remember goood old “Worms”?). Of course setting random numbers for those values every second or so would look awfully choppy.
I would rather have some kind of smooth oscillation in a given value range. Sort of like a sine wave but much more random.
Does anyone get what I’m after? 😉
Any ideas on how to achieve this kind of behavior would be appreciated.
If you want the delta (change) to be small, just generate a small random number for the delta.
For example, instead of:
use something like:
That way, your wind speed is still kept within the required bounds and it only ever changes gradually.
This will work for absolute values like speed, and also for direction if the thing you’re changing gradually is the angle from a fixed direction.
It can pretty well be used for any measurement.
Alternatively, if you want to ensure that the windspeed changes with a possibly large delta, but slowly, you can generate your target windspeed as you currently do but move gradually toward it: