static public string ReadTextRandomLine(this Stream item, RandIntSource source) { StreamReader reader = new StreamReader(item); if (item.CanSeek) { item.Position = source.GetIndex((int)item.Length); if (reader.ReadLine() != null) { string line = reader.ReadLine(); if (line != null) { return(line); } } item.Position = 0; return(reader.ReadLine()); } return(reader.ReadLines().ToList().GetRandom(source)); }
static public int GetIndex(int count) { return(SOURCE.GetIndex(count)); }
static public T GetRandom <T>(this IList <T> item, RandIntSource source) { return(item.Get(source.GetIndex(item.Count))); }
static public void RemoveEndingRandom <T>(this IList <T> item, RandIntSource source, int index_limit = 0) { item.RemoveEnding(source.GetIndex(item.Count).BindAbove(index_limit)); }
static public void RemoveBeginningRandom <T>(this IList <T> item, RandIntSource source, int index_limit = int.MaxValue) { item.RemoveBeginning(source.GetIndex(item.Count).BindBelow(index_limit)); }