fix: Codegens promo items (#1355)

This commit is contained in:
Kamron Batman 2023-02-26 00:48:27 -08:00 • committed by GitHub
parent bf6da39176
commit 8e3facc57b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
61 changed files with 1430 additions and 1923 deletions

View file

@ -1036,6 +1036,27 @@ public static class Utility
return sampleList;
}
public static void RandomSample<T>(this T[] source, int count, List<T> dest)
{
if (count <= 0)
{
return;
}
var length = source.Length;
Span<bool> list = stackalloc bool[length];
var i = 0;
do
{
var rand = Random(length);
if (!(list[rand] && (list[rand] = true)))
{
dest.Add(source[rand]);
}
} while (++i < count);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T RandomList<T>(params T[] list) => list.RandomElement();