private Country[] GetShuffeledCountries(Random random, Country[] countries) { List<int> shuffeled = new List<int>(); for (int i = 0; i < NumberOfChoices; i++) { shuffeled.Add(i); } // Now shuffel for (int i = NumberOfChoices; i > 1; i--) { int k = random.Next(0, i); int value = shuffeled[k]; shuffeled[k] = shuffeled[i - 1]; shuffeled[i - 1] = value; } var shuffeledCountries = new Country[NumberOfChoices]; var t = 0; foreach (var c in shuffeled) { shuffeledCountries[t] = countries[c]; t++; } return shuffeledCountries; }
/// <summary> /// /// </summary> /// <param name="id">Answer to the question</param> /// <param name="count">Random other answers</param> /// <returns></returns> private Country[] GetCountries(List<int> ids) { var countries = new Country[ids.Count]; var db = new CountriesRepository(); int i = 0; foreach (var id in ids) { countries[i] = GetCountry(db, id); i++; } return countries; }