If you want the delta (change) to be small, just generate a small random number for the delta.
For example, instead of:
windspeed = random (100)
use something like:
windspeed = windspeed - 4 + random (9) # -4 + 0..8 gives -4..4 if windspeed > 99: windspeed = 99 if windspeed < 0: windspeed = 0
Thus, your wind speed is still within the required boundaries, and it only gradually changes.
This will work for absolute values ββsuch as speed, as well as for direction if the thing you are gradually changing is the angle from a fixed direction.
It can be well used for any measurement.
Alternatively, if you want the wind speed to change with the greatest possible delta, but slowly, you can generate the target wind speed, as you are doing now, but gradually move towards it:
windspeed = 50 target = windspeed while true: # Only set new target if previous target reached. if target == windspeed: target = random (100) # Move gradually toward target. if target > windspeed: windspeed = windspeed + max (random (4) + 1, target - windspeed) else: windspeed = windspeed - max (random (4) + 1, target - windspeed) sleep (1)
source share