Skip to content

Commit

Permalink
Updated Random item extension
Browse files Browse the repository at this point in the history
  • Loading branch information
omegaleo committed Nov 27, 2023
1 parent f943ff3 commit ceb612e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Runtime/Extensions/IListExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ public static IList<T> Replace<T>(this IList<T> list, T originalValue, T valueTo
public static T Random<T>(this IList<T> list)
{
if (list.Count == 0) return default;

// Updated based on Robin King's tip about random items https://twitter.com/quoxel/status/1729137730607841755/photo/1
int seed = (int)DateTime.Now.Ticks;

var r = new System.Random();
var r = new Random(seed);

var randomIndex = r.Next(list.Count);
var randomIndex = r.Next(0, list.Count);

var returnValue = list[randomIndex];

Expand Down

0 comments on commit ceb612e

Please sign in to comment.