Skip to content

Commit

Permalink
Added Random method to Array and List. (#58)
Browse files Browse the repository at this point in the history
* Added Random method to Array and List.

* Renamed variables.
  • Loading branch information
neogeek committed Nov 30, 2018
1 parent d48914f commit eb0bacd
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Scripts/CustomExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,28 @@ public static List<List<T>> Permutations<T>(this List<T> list)

}

/// <summary>
/// Returns a random item from a List.
/// </summary>
/// <returns><typeparamref name="T"/></returns>
public static T Random<T>(this List<T> _items)
{

return _items[UnityEngine.Random.Range(0, _items.Count)];

}

/// <summary>
/// Returns a random item from an Array.
/// </summary>
/// <returns><typeparamref name="T"/></returns>
public static T Random<T>(this T[] _items)
{

return _items[UnityEngine.Random.Range(0, _items.Length)];

}

/// <summary>
/// Creates a new copy of a list and shuffles the values.
/// </summary>
Expand Down

0 comments on commit eb0bacd

Please sign in to comment.