diff options
author | chai <chaifix@163.com> | 2020-12-30 20:59:04 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-12-30 20:59:04 +0800 |
commit | e9ea621b93fbb58d9edfca8375918791637bbd52 (patch) | |
tree | 19ce3b1c1f2d51eda6878c9d0f2c9edc27f13650 /Client/Assembly-CSharp/RandomFill.cs |
+init
Diffstat (limited to 'Client/Assembly-CSharp/RandomFill.cs')
-rw-r--r-- | Client/Assembly-CSharp/RandomFill.cs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/RandomFill.cs b/Client/Assembly-CSharp/RandomFill.cs new file mode 100644 index 0000000..352eafd --- /dev/null +++ b/Client/Assembly-CSharp/RandomFill.cs @@ -0,0 +1,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]; + } +} |