public FrequencyElementGenerator(IEnumerable <T> elements, IRandom random)
        {
            elements.ThrowIfNull("elements");

            var counts = new Dictionary <T, float>();

            foreach (var element in elements)
            {
                if (counts.ContainsKey(element))
                {
                    counts[element]++;
                }
                else
                {
                    counts[element] = 1;
                }
            }

            var indexGenerator = new FrequencyIntGenerator(counts.Values, random);

            elementGenerator = new ListSelectorGenerator <T>(counts.Keys, indexGenerator);
        }
        public RandomElementGenerator(IEnumerable <T> list, IRandom random)
        {
            list.ThrowIfNull("list");

            generator = new ListSelectorGenerator <T>(list, new UniformIntGenerator(list.Count(), random));
        }