mysimulation/server/tso.common/Utils/CollectionUtils.cs
Tony Bark 22191ce648 Removed NioTSO client and server
- NioTSO client isn't needed because we're using RayLib
- Added FreeSO's API server to handle most backend operations
2024-05-01 02:55:43 -04:00

51 lines
1.3 KiB
C#
Executable file

using System;
using System.Collections.Generic;
namespace FSO.Client.Utils
{
public static class CollectionUtils
{
public static void Shuffle<T>(this IList<T> list)
{
Random rng = new Random();
int n = list.Count;
while (n > 1)
{
n--;
int k = rng.Next(n + 1);
T value = list[k];
list[k] = list[n];
list[n] = value;
}
}
public static IEnumerable<TResult> Select<TSource, TResult>(this Array items, Func<TSource, TResult> converter)
{
var result = new List<TResult>();
foreach (var item in items)
{
result.Add(converter((TSource)item));
}
return result;
}
public static Dictionary<TKey, TValue> Clone<TKey, TValue>(Dictionary<TKey, TValue> input)
{
var result = new Dictionary<TKey, TValue>();
foreach (var val in input)
{
result.Add(val.Key, val.Value);
}
return result;
}
private static Random RAND = new Random();
public static T RandomItem<T>(this T[] items)
{
var index = RAND.Next(items.Length);
return items[index];
}
}
}