Example #1
0
        /// <summary>
        /// Creates an unordered array of subsetCount long indices that
        /// constitute a subset of all longs in the range  [0, count-1].
        /// O(subsetCount) for subsetCount &lt;&lt; count.
        /// NOTE: It is assumed that subsetCount is significantly smaller
        /// than count. If this is not the case, use
        /// CreateRandomSubsetOfSize instead.
        /// WARNING: As subsetCount approaches count execution time
        /// increases significantly.
        /// </summary>
        public static long[] CreateSmallRandomSubsetIndexArrayLong(
            this IRandomUniform rnd, long subsetCount, long count)
        {
            Requires.That(subsetCount >= 0 && subsetCount <= count);
            var subsetIndices = new LongSet(subsetCount);

            for (int i = 0; i < subsetCount; i++)
            {
                long index;
                do
                {
                    index = rnd.UniformLong(count);
                }while (!subsetIndices.TryAdd(index));
            }
            return(subsetIndices.ToArray());
        }
Example #2
0
        /// <summary>
        /// Creates an unordered array of subsetCount long indices that
        /// constitute a subset of all longs in the range  [0, count-1].
        /// O(subsetCount) for subsetCount &lt;&lt; count.
        /// NOTE: It is assumed that subsetCount is significantly smaller
        /// than count. If this is not the case, use
        /// CreateRandomSubsetOfSize instead.
        /// WARNING: As subsetCount approaches count execution time
        /// increases significantly.
        /// </summary>
        public static long[] CreateSmallRandomSubsetIndexArrayLong(
            this IRandomUniform rnd, long subsetCount, long count)
        {
            if (!(subsetCount >= 0 && subsetCount <= count))
            {
                throw new ArgumentOutOfRangeException(nameof(subsetCount));
            }
            var subsetIndices = new LongSet(subsetCount);

            for (int i = 0; i < subsetCount; i++)
            {
                long index;
                do
                {
                    index = rnd.UniformLong(count);
                }while (!subsetIndices.TryAdd(index));
            }
            return(subsetIndices.ToArray());
        }