Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System.Collections.Generic;
using UnityEngine;
public static class ListExtensionMethods
{
public static T PickRandom<T>(this IList<T> list)
{
T result = default(T);
if (list.Count > 0)
{
result = list[Random.Range(0, list.Count)];
}
return result;
}
public static void Shuffle<T>(this IList<T> list)
{
int n = list.Count;
while (n > 1)
{
n--;
int k = Random.Range(0, n + 1);
T value = list[k];
list[k] = list[n];
list[n] = value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.