Skip to content

Instantly share code, notes, and snippets.

@jakeobrien
Created May 2, 2013 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jakeobrien/5503948 to your computer and use it in GitHub Desktop.
Save jakeobrien/5503948 to your computer and use it in GitHub Desktop.
Shuffle logic for Domino! bones
// for native iOS (Objective-C)
srand((unsigned)time(NULL));
NSUInteger count = [bones count];
for (NSUInteger i = 0; i < count; ++i) {
int nElements = count - i;
int n = (rand() % nElements) + i;
[bones exchangeObjectAtIndex:i withObjectAtIndex:n];
}
// for Unity (C#)
public static void Shuffle<T>(this List<T> list)
{
System.Random rnd = new System.Random();
int n = list.Count;
while (n > 1) {
n--;
int k = rnd.Next(n + 1);
T obj = list[k];
list[k] = list[n];
list[n] = obj;
}
}
@themartorana
Copy link

Hi! Dave here. This is the actual code that we are using to randomize bones. Up top is what we are currently using for iOS. Below that - "For Unity (C#)" - is the new code that we will be using in our Android and future iOS app.

If you have any questions or comments about this, let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment