Forums

Full Version: Use of srand()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
There is a srand() in src/particles.cpp. The seed value is fixed as 1337. If I change the seed value to time(), will it cause any problem elsewhere? I'd like to race against random AI cars. It wouldn't feel quite random if the AI car always come in the same sequence.
That sounds like a good idea. I suspect Joe was just being lazy not using time() (and also trying to be 31337 apparently Smile )...
The srand in particles.cpp has nothing to do with the AI. That's the code that generates tire smoke when your tires lose grip. Changing the srand value will just result in different patterns of smoke, which I bet you'd never even notice.
Doesn't the random seed apply everywhere in the program if you use srand()?
The only place rand is used is for the particles... hmm, and I guess, for the color of the AI car. Is that what you meant? If so, then I misunderstood and thought you meant the actual driving of the AI (which won't change as it's not random).
Just to clear things up, the AI algorithm does not use random value. What I wanted to do is changing the car selection code so every time you race against a random opponent car. And to do that, I need to change the srand() to use a non-fixed seed. I'm thinking of just changing the srand() in particles.cpp instead of calling srand() again.
I think having a random opponent would be cool, and since we have multiple things that use the random seed, why not seed it in main() before the particle system is used or AI player is selected?
Originally the particle system was the only thing using rand. Since that's no longer the case, then sure, put the seed in main. Or better yet, write a simple RANDOM class that does a seed as part of the constructor.
I'll move the srand() call to main.cpp.