public void FailsWhenFirstArgIsNull() { var rng = new Random(); IEnumerable <int> a = null; Assert.Throws <ArgumentNullException>(() => ShuffleOps.ShuffleCopy(a, rng)); }
public void FailsWhenSecondArgIsNull() { Random rng = null; var a = new List <int> { 1, 2, 3 }; Assert.Throws <ArgumentNullException>(() => ShuffleOps.ShuffleCopy(a, rng)); }
public void Works() { var rng = new Random(Seed: 5); var a = new List <int> { 1, 2, 3, 4, 5, 6 }; var b = ShuffleOps.ShuffleCopy(a, rng); Assert.Equal(new[] { 6, 1, 4, 5, 2, 3 }, b); }
private static void Example2() { var rng = new Random(Seed: 5); var a = new List <int> { 1, 2, 3, 4, 5, 6 }; var b = ShuffleOps.ShuffleCopy(a, rng); Console.WriteLine(string.Join(", ", b)); }
public IChromosome GenerisiRandomTestSaOblastima(List <int> oblasti, int Length) { List <Question> questionsNova = new List <Question>(); Test result = null; Random r = new Random(); do { //Bira iz banke nasumicno pitanja samo koja sadrze te oblasti var questionsDomain = GetQuestionsWhichContainDomains(oblasti); questionsNova.AddRange(ShuffleOps.ShuffleCopy <Question>(questionsDomain, r).Take(Length - questionsNova.Count)); questionsNova = questionsNova.Distinct().ToList(); result = new Test(questionsNova, Length); }while (result.HasDuplicate()); return(result); }
/// <summary>Returns a shuffled array of an <see cref="IEnumerable{T}"/>.</summary> /// <typeparam name="T">Type of items in <paramref name="source"/>.</typeparam> /// <param name="source">The enumerable to shuffle.</param> /// <param name="randomNumberGenerator">The random number generator to use.</param> /// <exception cref="ArgumentNullException">If <paramref name="source"/> is null - or <paramref name="randomNumberGenerator"/> is null.</exception> public static T[] ShuffleCopy <T>(this IEnumerable <T> source, Random randomNumberGenerator) => ShuffleOps.ShuffleCopy(source, randomNumberGenerator);