Assuming the random number generator is declared as follows:
public static Random Rnd = new Random();
Allows you to define the Shuffle function to put the list in random order:
/// <summary> /// Brings the elements of the given list into a random order /// </summary> /// <typeparam name="T">Type of elements in the list.</typeparam> /// <param name="list">List to shuffle.</param> /// <returns>The list operated on.</returns> public static IList<T> Shuffle<T>(this IList<T> list) { if (list == null) throw new ArgumentNullException("list"); for (int j = list.Count; j >= 1; j--) { int item = Rnd.Next(0, j); if (item < j - 1) { var t = list[item]; list[item] = list[j - 1]; list[j - 1] = t; } } return list; }
This implementation of Shuffle is kindly provided by romkyns!
Now just put the methods on a list, shuffle, and then run them:
var list = new List<Action> { A, B, C }; list.Shuffle(); list.ForEach(method => method());
Timwi
source share