Beispiel #1
0
        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));
        }
Beispiel #2
0
 static public int GetIndex(int count)
 {
     return(SOURCE.GetIndex(count));
 }
Beispiel #3
0
 static public T GetRandom <T>(this IList <T> item, RandIntSource source)
 {
     return(item.Get(source.GetIndex(item.Count)));
 }
Beispiel #4
0
 static public void RemoveEndingRandom <T>(this IList <T> item, RandIntSource source, int index_limit = 0)
 {
     item.RemoveEnding(source.GetIndex(item.Count).BindAbove(index_limit));
 }
Beispiel #5
0
 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));
 }