Skip to content

Commit f43030d

Browse files
committed
chore(Random): Add shuffle to collection
1 parent e2a38c0 commit f43030d

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

Assets/JCSUnity/Scripts/Util/JCS_Random.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ private static float FindDecimalInclude(float num)
223223
}
224224

225225
/// <summary>
226-
/// Choose object(s) from the collections.
226+
/// Choose object(s) from the collection.
227227
/// </summary>
228228
public static T ChooseOneE<T>(params T[] args) // Ellipsis
229229
{
@@ -249,10 +249,6 @@ public static List<T> Choose<T>(int size, ICollection<T> lst)
249249

250250
return chosen;
251251
}
252-
253-
/// <summary>
254-
/// Choose object(s) from the collection.
255-
/// </summary>
256252
public static KeyValuePair<T, K> ChooseOneE<T, K>(params KeyValuePair<T, K>[] args) // Ellipsis
257253
{
258254
return ChooseOne(args);
@@ -290,6 +286,26 @@ public static T EnumValue<T>()
290286
return (T)v.GetValue(r.Next(v.Length));
291287
}
292288

289+
/// <summary>
290+
/// Return a shuffled collection.
291+
/// </summary>
292+
public static ICollection<T> ShuffleE<T>(params T[] col)
293+
{
294+
return Shuffle(col);
295+
}
296+
public static ICollection<T> Shuffle<T>(ICollection<T> col)
297+
{
298+
return col.OrderBy(x => Random.value).ToArray();
299+
}
300+
public static ICollection<KeyValuePair<T, K>> ShuffleE<T, K>(params KeyValuePair<T, K>[] dict)
301+
{
302+
return Shuffle(dict);
303+
}
304+
public static ICollection<KeyValuePair<T, K>> Shuffle<T, K>(ICollection<KeyValuePair<T, K>> dict)
305+
{
306+
return dict.OrderBy(x => Random.value).ToArray();
307+
}
308+
293309
/// <summary>
294310
/// Return a random point in bounds.
295311
/// </summary>

0 commit comments

Comments
 (0)