July 18, 200421 yr 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
July 18, 200421 yr You might try using the last two digits of TICK18. Again, this is not completely random, but probably close enough.Doug
July 18, 200421 yr 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
Create an account or sign in to comment