rand() keeps giving me the same values?

Started by
18 comments, last by Servant of the Lord 11 years, 3 months ago
I can't see you declaring any Zombies in the code you posted, so I assume you do so globally before the WinMain function. If so, then the constructors will be called before srand().

The code posted isn't the full code, it's just what I thought was relevant. the full source was just uploaded in the previous post if you'd like to have a look :)

The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky
Advertisement

try putting srand(time(0)) where you place srand(rand()) or before you generate the position data to test check if it changes at all. Also, check your position update function for any code that might be doing something you dont want.

the full source was just uploaded in the previous post if you'd like to have a look

That filehost is useless. Each time I click the link it emails me it takes me to a page asking me what file I want to download so that they can email me a link to it.
the full source was just uploaded in the previous post if you'd like to have a look

That filehost is useless. Each time I click the link it emails me it takes me to a page asking me what file I want to download so that they can email me a link to it.

I tried the link myself and everything seemed to work fine. What hosting site would you prefer? :)

The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky


the full source was just uploaded in the previous post if you'd like to have a look


That filehost is useless. Each time I click the link it emails me it takes me to a page asking me what file I want to download so that they can email me a link to it.



I tried the link myself and everything seemed to work fine. What hosting site would you prefer? smile.png



It turns out their site just doesn't like OPera, it worked for me in IE.

And yes, you do declare your zombies globally in GameSkel.cpp, so their position is being set before your WinMain function is even started.

That webhost also doesn't like Google Chrome (and also refuses @mailinator.com addresses huh.png).

But I'm glad the problem was resolved, thanks Lenny!

Classes in the global scope get constructed before code enters the main() (or WinMain()) function. Really, globals should be avoided, but it's understandable for small programs - you just have to be very aware of the construction-order problems (there's no garuntee in what order the classes will be constructed if they are in the global scope, but they are guaranteed to be constructed before entering the main entry point function).

Okay, thank you so much everyone :)

The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky

So what can I do to resolve the issue? What are the alternatives to using Globals?

The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky
You can declare them inside your WinMain() function, which will require you to then pass the array to any functions that need to access the Zombies.

If you want to minimize code changes, you can change your declaration of test to a pointer to a Zombie, and then inside your WinMain function, use new[] to allocate the space.

Better yet, use a std::vector, and push_back() the Zombies. If you have to, std::vector could be global, but your push_backs() need to be inside a function, so the Zombies are constructed from within the functions after srand() is called.

This topic is closed to new replies.

Advertisement