using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ListHelper {
    public static void Shuffle<T>(IList<T> list)
    {
        for (int i = 0; i < list.Count; i++)
            Swap(list, i, Random.Range(i, list.Count));
    }

    public static void Swap<T>(IList<T> list, int i, int j)
    {
        var temp = list[i];
        list[i] = list[j];
        list[j] = temp;
    }

    public static T DrawFromAtRandom<T>(IList<T> list)
    {
        if (list == null || list.Count == 0)
            return default(T);

        int idx = Random.Range(0, list.Count);
        return list[idx];
    }

    public static T RemoveFromAtRandom<T>(IList<T> list)
    {
        T item = DrawFromAtRandom(list);
        list.Remove(item);
        return item;

    }
}
