swb_shared/util/TableUtil.cs

Small utility class with a single generic helper. Provides GetRandom<T> which returns a random element from an IList<T> or default(T) when the list is empty.

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];
	}
}