2016-07-09 22:30:12 +00:00
|
|
|
|
using System;
|
2017-12-15 04:58:55 +00:00
|
|
|
|
using System.Collections.Generic;
|
2016-07-09 22:30:12 +00:00
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-07-09 22:30:12 +00:00
|
|
|
|
{
|
2018-05-12 19:28:48 +00:00
|
|
|
|
public static partial class Util
|
2016-07-09 22:30:12 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static readonly Random Rand = new Random();
|
2018-07-29 20:27:48 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static uint Rand32()
|
2016-07-09 22:30:12 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return (uint)Rand.Next(1 << 30) << 2 | (uint)Rand.Next(1 << 2);
|
2016-07-09 22:30:12 +00:00
|
|
|
|
}
|
2017-12-15 04:58:55 +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)
|
2016-07-09 22:30:12 +00:00
|
|
|
|
{
|
2017-12-15 04:58:55 +00:00
|
|
|
|
int n = items.Count;
|
2016-07-09 22:30:12 +00:00
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
|
{
|
2019-02-07 07:28:02 +00:00
|
|
|
|
int index = i + Rand.Next(n-i);
|
|
|
|
|
T t = items[index];
|
|
|
|
|
items[index] = items[i];
|
2017-12-15 04:58:55 +00:00
|
|
|
|
items[i] = t;
|
2016-07-09 22:30:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|