Пример #1
0
        public void generatePods(Tier tier)
        {
            int             podCount           = (int)Math.Floor(lc.PodAmount * (lc.nStorageBlocks() * lc.nStorageLocationsPerBlock()));
            List <Waypoint> potentialWaypoints = tier.Waypoints.Where(wp => wp.PodStorageLocation).ToList();

            for (int i = 0; i < podCount; i++)
            {
                int      waypointIndex  = rand.NextInt(potentialWaypoints.Count);
                Waypoint chosenWaypoint = potentialWaypoints[waypointIndex];
                Pod      pod            = instance.CreatePod(instance.RegisterPodID(), tier, chosenWaypoint, lc.PodRadius, orientationPodDefault, lc.PodCapacity);
                potentialWaypoints.RemoveAt(waypointIndex);
            }
        }
Пример #2
0
        /// <summary>
        /// Selects a random element of an enumerable.
        /// </summary>
        /// <typeparam name="T">The generic type of the enumerable.</typeparam>
        /// <param name="enumerable">The enumerable.</param>
        /// <param name="randomizer">The randomizer.</param>
        /// <returns>The randomly selected element.</returns>
        public static T SelectRandom <T>(this IEnumerable <T> enumerable, IRandomizer randomizer)
        {
            var list  = enumerable as IList <T> ?? enumerable.ToList();
            var index = randomizer.NextInt(0, list.Count);

            return(list[index]);
        }
 public static void Shuffle <T>(this T[] @array, IRandomizer randomizer)
 {
     for (int i = 0; i < array.Length; i++)
     {
         int newPos = randomizer.NextInt(i, array.Length - 1);
         if (newPos != i)
         {
             T tmp = @array[i];
             @array[i]      = @array[newPos];
             @array[newPos] = tmp;
         }
     }
 }
Пример #4
0
 /// <summary>
 /// Returns a random boolean
 /// </summary>
 /// <param name="r"></param>
 /// <returns></returns>
 public static bool NextBool(this IRandomizer r) => r.NextInt(2) == 1;
Пример #5
0
 /// <summary>
 /// Returns a random integer greater or equal to the start of the
 /// Range and less than the end of the Range
 /// </summary>
 /// <param name="r"></param>
 /// <param name="range"></param>
 /// <returns></returns>
 public static int NextInt(this IRandomizer r, Range range) => r.NextInt(range.Start.Value, range.End.Value);
Пример #6
0
 /// <summary>
 /// Returns a random integer greater or equal to 0 and less
 /// than the supplied maxValue
 /// </summary>
 /// <param name="r"></param>
 /// <param name="maxValue"></param>
 /// <returns></returns>
 public static int NextInt(this IRandomizer r, int maxValue) => r.NextInt(0, maxValue);
Пример #7
0
 /// <summary>
 /// Returns a random integer greater or equal to 0 and less
 /// than int.MaxValue
 /// </summary>
 /// <param name="r"></param>
 /// <returns></returns>
 public static int NextInt(this IRandomizer r) => r.NextInt(0, int.MaxValue);
Пример #8
0
 /// <summary>
 /// Returns a random DateTime greater or equal to the supplied startDateTime and less than
 /// the supplied endDateTime
 /// </summary>
 /// <param name="r"></param>
 /// <param name="startDateTime"></param>
 /// <param name="endDateTime"></param>
 /// <returns></returns>
 public static DateTime NextDateTime(this IRandomizer r, DateTime startDateTime, DateTime endDateTime) =>
 startDateTime.AddDays(r.NextInt((endDateTime - startDateTime).Days));