Jump to content
Sign in to follow this  
Guest bartels

Creating Better Random Number with C++ and the MingGW Compiler

Recommended Posts

Guest Bryan

Hi, in one of my gauges I need to create a random number between 1 and 100.This is my code so far. time1 = CLOCK_MINUTEvar.var_value.n ; int seed = time1; srand(seed); random= (rand()%100);It works ok, but the the generated "random" number isn't really that random. For example, if the Clock_Minute variable equals 44 minutes, the "random" generated number is always 82. Can anyone think of a way to bolster the "randomness" of this code?I'm using the MingGW compilier with the Easy Gauge Programmer's Ed.Thanks, Bryan

Share this post


Link to post
Share on other sites

You might try using the last two digits of TICK18. Again, this is not completely random, but probably close enough.Doug

Share this post


Link to post
Share on other sites
Guest bartels

As far as I know you shouldn't "reseed" the random sequence every time, especially no with the same value. I assume you only need to use srand once at gauge loadup, or at least not with repitive numbers (e.g. srand((unsigned)time( NULL ) ); or ELAPSED_SECONDS instead of CLOCK_MINUTE). Arne Bartels

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...