Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / problem with random numbers

Author
Message
MHS
15
Years of Service
User Offline
Joined: 16th Aug 2009
Location:
Posted: 24th Sep 2009 08:31
hello everyone
is there any way to make random numbers in a loop?
for example look at my project down there. in function "Fight" containing function "Player Attack(Monster& monster)" and function "Monster Attack(Player& player)" i want random numbers to be made everytime loop executes but when i run it, it always make the same number (of course it changes in each run time). can you suggest any change to make it work the way i want?
do not care about a lot of garbages in my code! i've made a lot of tests and didn't delete them.
explanation of project and function "Fight" is also in the zip folder.
thanks

Attachments

Login to view attachments
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 24th Sep 2009 19:21 Edited at: 24th Sep 2009 19:21
Move your

srand (time(0));

to the beginning of the program. You keep reseeding the random number generator when you only need to seed it once. If you're creating monsters close together the time(0) will likely reseed the generator with the same value so you'll get the same sequence.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
MHS
15
Years of Service
User Offline
Joined: 16th Aug 2009
Location:
Posted: 29th Sep 2009 08:47
thanks Lilith!
it's working well now

Login to post a reply

Server time is: 2024-11-20 15:30:44
Your offset time is: 2024-11-20 15:30:44