swb_shared/util/TableUtil.cs

A small utility class with a single generic method that returns a random element from an IList<T>. It returns default(T) if the list is empty and uses Random.Shared for selection.

using System;
using System.Collections.Generic;

/* 
 * Utility class for tables
*/

namespace SWB.Shared;

class TableUtil
{
	public static T GetRandom<T>( IList<T> list )
	{
		if ( list.Count == 0 ) return default;

		var randI = Random.Shared.Next( list.Count );
		return list[randI];
	}
}