array value shuffle -- need help!
Displaying 1-3 of 3 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
IkimashoZ

What is the easiest/most efficient ways to shuffle the values in an array? PHP has a function like this. I want to take all the values in an array and randomize their keys. Anyone ever programmed a function like this before?

Posted on 2007-09-12 15:10:16

zonker6666

heres a simple way to do it

void flip(int ida, int idb)
{
int t=array[ida];
array[ida]=array[idb];
array[idb]=t;
}

void shuffle()
{
int i;
for(i=0;i<arraysize;i++)
{
flip(Random(0,arraysize-1),Random(0,arraysize-1));
}
}

Posted on 2007-09-12 16:15:13

IkimashoZ

Awesome! That works for me. Thanks!

Posted on 2007-09-12 21:34:56


Displaying 1-3 of 3 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.