1
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Unity.Mathematics;
|
||||
using Random = System.Random;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
@@ -198,6 +200,22 @@ namespace BITKit
|
||||
{
|
||||
return self[typeof(TKey)];
|
||||
}
|
||||
|
||||
public static TValue[] TakeRandom<TValue>(this TValue[] self, int count)
|
||||
{
|
||||
//自动实现
|
||||
var random = new Random();
|
||||
var newList = self.ToList();
|
||||
count = math.min(count, newList.Count);
|
||||
var result = new TValue[count];
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var value = newList[random.Next(0, newList.Count)];
|
||||
newList.Remove(value);
|
||||
result[i] = value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static TValue Get<TKey, TValue>(this IDictionary<TKey, TValue> self, TKey key) where TValue : new()
|
||||
{
|
||||
lock (self)
|
||||
|
Reference in New Issue
Block a user