ソースコード
using System.Collections.Generic; using UnityEngine; public static class ListExt { public static T PopRandomElement<T>( this List<T> self ) { var item = self[ Random.Range( 0, self.Count ) ]; self.Remove( item ); return item; } }
使い方
var list = new List<int> { 1, 2, 3, 4, 5 }; var value = list.PopRandomElement();