Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8624769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:36:51+00:00 2026-06-12T07:36:51+00:00

Could anyone give me a hint on how to generate smooth random numbers? Here’s

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:36:52+00:00Added an answer on June 12, 2026 at 7:36 am

    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)                # 0 thru 99 inclusive
    

    use something like:

    windspeed = windspeed - 4 + random (9)  # -4 + 0..8 gives -4..4
    if   windspeed > 99: windspeed = 99
    elif windspeed <  0: windspeed =  0
    

    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:

    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)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could anyone give me examples, how I could use diffstat with subversion? I mean,
Could anyone give me some help with this please? The content needs to appear
Could anyone give some pointers on why the impure computations in Haskell are modelled
Could anyone give me example code to access the command line through VBScript? I
Could anyone give an example program that explains Java Threads in a simple way?
Could anyone give me an example about how to do fuzzy matching of two
Hi Could anyone give me a sample program to Create an ApplyRemoveConst template that
Could anyone please give a sample or any link that describes how to spawn
I was wondering if anyone could give me an example or point me to
I am using Eclipse 3.6, and want to add Richfaces to Palette.Could anyone give

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.