This isn't my code. A 'friend' gave this to me to fix. I can't figure out why it keeps returning the same number when its suppose to be different each time(rand() is used).
This isn't my code. A 'friend' gave this to me to fix. I can't figure out why it keeps returning the same number when its suppose to be different each time(rand() is used).
My friend hasn't downloaded the source but he wonders if you have seeded the random number generator using srand(). You may want to check it out, but I wouldn't pay too much attention as this friend can be a real pain in the ass.
Joe
Joe is right on this one there is no srand(); in your code put that line in to fix your probelm.
Very funny. I'm serious I didn't code this. If I wanted to make a tetris game then I'd do it on the WinAPI since GDI makes graphics alot easier.
I've looked at the source code and srand() has been used.
I didnt see a srand in there..... if he is running it threw the compiler it will usually give you the same number even if srand is used...
Well, I gave up on the code.
If you're interested AIM Jesusitron. Hes the guy who coded this. Give him the advice. Hes too stubborn, I tried giving him the link to this page but hes too busy trying to figure out whats wrong with his source code. Send him an instant message to grab his attention and help.
I see the srand now... the fix is :
1) put srand(clock()); in main
2) on his srand he is using a constant a constant will ALWAYS generate the same number pattern
I've just given my friend a good seeing too (he no longer has any eyebrows). His next suggestion is
make sure your only calling srand once
If you're calling it within a certain timeframe you'll just keep seeding rand with the same number.
I hope this is right, or there may be more than eyebrows at stake.
Joe
Random numbers are crappy. That's the bottom line.
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials