Rand is the same every time.

Started by
3 comments, last by fastcall22 11 years, 2 months ago

uhm... title. Please help me the source code is below:

https://github.com/Kripis/-O/blob/master/Dinky%20Island

Advertisement
You roll arrayChooser once at program start, but then you don't ever re-roll it as you move, so whatever the event is chosen to be at program start is what it will always be as you play.
Stunning... the usual answer (without looking at your code) would be: "Beginner error: you forgot to call srand or you are calling srand with the same value every time before calling rand". But, your code actually looks perfectly correct...

FleBlanc is correct. The variable arrayChooser never changes because you only call rand() once before the loop.

How could I fix this?? make a loop before the main loop that changed arrayChooser every time?

Move line 16 after line 26.

This topic is closed to new replies.

Advertisement