private static void SwapRandomBones(int numToSwap, ArrayProperty <NameProperty> trackBoneNames) { if (trackBoneNames.Count < 2) { return; // There is nothing to swap } int i = 0; while (i < numToSwap) { var index1 = trackBoneNames.RandomIndex(); var bn = trackBoneNames[index1]; int numTries = 10; while (numTries > 0 && bonegroupsToNeverRandomize.Any(x => x.Contains(bn.Value, StringComparison.InvariantCultureIgnoreCase))) { index1 = trackBoneNames.RandomIndex(); bn = trackBoneNames[index1]; numTries--; } if (numTries < 0) { return; // Don't try, we could not find a bone to swap to } int index2 = index1; while (numTries > 0 && (index2 == index1 || bonegroupsToNeverRandomize.Any(x => x.Contains(bn.Value, StringComparison.InvariantCultureIgnoreCase)))) { index2 = trackBoneNames.RandomIndex(); bn = trackBoneNames[index2]; numTries--; } if (numTries < 0) { return; // Don't try, we could not find a bone to swap to } // Swap em' var item1 = trackBoneNames[index1]; trackBoneNames[index1] = trackBoneNames[index2]; trackBoneNames[index2] = item1; i++; } }