Forums » C++ Framework » (SOLVED) Random returning same value »
| Diori Cergy Castali | (SOLVED) Random returning same value | ||||
|---|---|---|---|---|---|
|
Added by Diori Cergy Castali 10 months ago
Im trying to generate a lot of objects that contain randomized sprite. the random works, but all the 70 items always have the same image (second random always same with the first). randomItem(Item* pItem)
srand(time(0));
switch((rand() % 10) + 1)
{
case 1 :
pItem->updateAll("Apple.png","Apple");
break;
case 2 :
pItem->updateAll("Basket1.png","Basket");
break;
//case ...
SOLVED the srand(time(0)) should be called once, so I put it out the loop. |
||||
| Alex Zhd | RE: (SOLVED) Random returning same value | ||||
|
I think, better use the |
||||
| Phill Jones | RE: (SOLVED) Random returning same value | ||||
|
Added by Phill Jones 10 months ago
arc4random() is an apple/iphone specific function isn't it? @Frizzlep |
(1-2/2)