public static T GetRandomItemFromList <T>(IList <T> list) { if (list == null || list.Count == 0) { return(default(T)); } return(list[RandomProxy.Next(list.Count)]); }
private string FillInRandomDataFromNumber(string format, char symbol = '#') { var result = format.ToCharArray(); for (int i = 0; i < result.Length; i++) { if (result[i] == symbol) { result[i] = (char)(RandomProxy.Next(10) + 48); } } return(new string(result)); }
internal bool GetProbablyFromFormat(ref string result) { const string pattern = @"{0.[0-9]+}"; var match = Regex.Match(result, pattern); if (!match.Success) { return(true); } result = result.Remove(match.Index, match.Length); float chance = 0f; float.TryParse(match.Value.Substring(1, match.Value.Length - 2), out chance); return(RandomProxy.NextBool(chance)); }
public static T[] GetMultipleRandomItemsFromList <T>(IList <T> list, int count) { List <T> result = new List <T>(count); for (int i = 0; i < list.Count; i++) { double p = (count - (double)result.Count) / ((double)list.Count - i); if (RandomProxy.NextBool(p)) { result.Add(list[i]); } if (result.Count >= count) { return(result.ToArray()); } } return(result.ToArray()); }