Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use of srand()
01-19-2007, 10:58 AM,
Use of srand()
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.
01-19-2007, 02:35 PM,
That sounds like a good idea. I suspect Joe was just being lazy not using time() (and also trying to be 31337 apparently Smile )...
01-19-2007, 10:12 PM,
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.
01-19-2007, 10:16 PM,
Doesn't the random seed apply everywhere in the program if you use srand()?
01-19-2007, 11:16 PM,
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).
01-20-2007, 11:15 AM,
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.
01-23-2007, 01:13 AM,
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?
01-23-2007, 02:41 AM,
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.
01-24-2007, 10:26 AM,
I'll move the srand() call to main.cpp.

Forum Jump:

Users browsing this thread: 1 Guest(s)