Use of srand() - rookie1 - 01-19-2007
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.
- thelusiv - 01-19-2007
That sounds like a good idea. I suspect Joe was just being lazy not using time() (and also trying to be 31337 apparently )...
- joevenzon - 01-19-2007
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.
- thelusiv - 01-19-2007
Doesn't the random seed apply everywhere in the program if you use srand()?
- joevenzon - 01-19-2007
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).
- rookie1 - 01-20-2007
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.
- thelusiv - 01-23-2007
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?
- joevenzon - 01-23-2007
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.
- rookie1 - 01-24-2007
I'll move the srand() call to main.cpp.
|