Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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());
        }