CCArray randomObject!


#1

Hi!
i would get a random sprite(object) from a CCArray.
and i have created a child to CCSprite with the name Gem
the array have seven objects.
i wrote:

Gem* gem = (Gem*)array->randomObject();
this->addChild(gem, 1);

BUT it is always the same, every time i simulate/debug it!
And it is always the first object!
Can someone plz tell me WHY!:slight_smile:
I appreciate ALL HELP!:slight_smile: :wink:


#2

I’m not sure about what this function really do.
but in most device use random generator algorithm which called pseudo-random which is not 100% random. It use seed to generate the number. so when you program random in c or else
u have to srand(time(NULL)); << this thing set seed to pseudo-random if you not set seed it will return in same random number in sequence.

Hope this help. And sorry for my bad English skill again :slight_smile:


#3

thanks, but i solved my self…
i don’t know that func, but what i did was just to make a function that i ran some times and every time it changed.
the problem with that was, that i just ran one time(the init function is just running one time) soooo that was the prob.
BUT Many THANKS for your help
I REALLY APPRECIATE IT!<3