blob: 352eafdf9b4079d9a5a915cadeed28b568032cd8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
using System;
using System.Collections.Generic;
using System.Linq;
public class RandomFill<T>
{
private T[] values;
private int idx;
public void Set(IEnumerable<T> values)
{
if (this.values == null)
{
this.values = values.ToArray<T>();
this.values.Shuffle<T>();
this.idx = this.values.Length - 1;
}
}
public T Get()
{
if (this.idx < 0)
{
this.values.Shuffle<T>();
this.idx = this.values.Length - 1;
}
T[] array = this.values;
int num = this.idx;
this.idx = num - 1;
return array[num];
}
}
|