PKHeX/PKHeX.Core/Util/RandUtil.cs

41 lines
1.3 KiB
C#
Raw Normal View History

2016-07-09 22:30:12 +00:00
using System;
using System.Collections.Generic;
2016-07-09 22:30:12 +00:00
namespace PKHeX.Core
2016-07-09 22:30:12 +00:00
{
public static partial class Util
2016-07-09 22:30:12 +00:00
{
public static readonly Random Rand = new Random();
2018-07-29 20:27:48 +00:00
public static uint Rand32()
2016-07-09 22:30:12 +00:00
{
return (uint)Rand.Next(1 << 30) << 2 | (uint)Rand.Next(1 << 2);
2016-07-09 22:30:12 +00:00
}
/// <summary>
/// Shuffles the order of items within a collection of items.
/// </summary>
/// <typeparam name="T">Item type</typeparam>
/// <param name="items">Item collection</param>
public static void Shuffle<T>(IList<T> items) => Shuffle(items, 0, items.Count);
/// <summary>
/// Shuffles the order of items within a collection of items.
/// </summary>
/// <typeparam name="T">Item type</typeparam>
/// <param name="items">Item collection</param>
/// <param name="start">Starting position</param>
/// <param name="end">Ending position</param>
public static void Shuffle<T>(IList<T> items, int start, int end)
2016-07-09 22:30:12 +00:00
{
for (int i = start; i < end; i++)
2016-07-09 22:30:12 +00:00
{
int index = i + Rand.Next(end - i);
T t = items[index];
items[index] = items[i];
items[i] = t;
2016-07-09 22:30:12 +00:00
}
}
}
}