Skip to content

Instantly share code, notes, and snippets.

@nicloay
Created November 14, 2017 14:34
Show Gist options
  • Save nicloay/a473e41da38b1c8bc621edd778deb800 to your computer and use it in GitHub Desktop.
Save nicloay/a473e41da38b1c8bc621edd778deb800 to your computer and use it in GitHub Desktop.
array utilities
using UnityEngine;
public static class ArrayUtil {
public static int[] GetSequenceArray(int length)
{
int[] result = new int[length];
for (int i = 0; i < length; i++)
{
result[i] = i;
}
return result;
}
public static void ShuffleArray<T>(T[] array)
{
if (array == null || array.Length < 2)
{
return; //do nothing
}
T temp;
for (int i = 0; i < array.Length; i++)
{
temp = array[i];
int rndId = Random.Range(0, array.Length);
array[i] = array[rndId];
array[rndId] = temp;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment