Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Linq;
- using System.Collections.Generic;
- public static class LinqExtensions {
- public static T Random<T>(this IEnumerable<T> list) {
- if (list != null && list.Any ())
- return list.ElementAt(UnityEngine.Random.Range(0, list.Count()));
- return default(T);
- }
- public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source) {
- var list = source.ToList();
- list.Shuffle();
- return list;
- }
- public static void Shuffle<T>(this IList<T> list) {
- int count = list.Count;
- while (count > 1) {
- int i = UnityEngine.Random.Range(0, count - 1);
- T temp = list[count];
- list[count] = list[i];
- list[i] = temp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement