26 lines
583 B
C#
26 lines
583 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SDL2Demo.Screenhacks
|
|
{
|
|
internal static class RandomExtensions
|
|
{
|
|
public static T? Pick<T>(this Random rng, T[] collection)
|
|
{
|
|
if (collection == null)
|
|
return default(T);
|
|
|
|
if (collection.Length == 0)
|
|
return default(T);
|
|
|
|
if (collection.Length == 1)
|
|
return collection[0];
|
|
|
|
return collection[rng.Next(collection.Length)];
|
|
}
|
|
}
|
|
}
|