mirror of
https://github.com/space-wizards/space-station-14.git
synced 2026-02-15 03:31:30 +01:00
Fluid spread refactor (#11908)
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Fix undefined
This commit is contained in:
28
Content.Shared/SharedArrayExtension.cs
Normal file
28
Content.Shared/SharedArrayExtension.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Shared;
|
||||
|
||||
public static class SharedArrayExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Randomizes the array mutating it in the process
|
||||
/// </summary>
|
||||
/// <param name="array">array being randomized</param>
|
||||
/// <param name="random">source of randomization</param>
|
||||
/// <typeparam name="T">type of array element</typeparam>
|
||||
public static void Shuffle<T>(this Span<T> array, IRobustRandom? random = null)
|
||||
{
|
||||
var n = array.Length;
|
||||
if (n <= 1)
|
||||
return;
|
||||
IoCManager.Resolve(ref random);
|
||||
|
||||
while (n > 1)
|
||||
{
|
||||
n--;
|
||||
var k = random.Next(n + 1);
|
||||
(array[k], array[n]) =
|
||||
(array[n], array[k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user