All pastes #909127 Raw Edit

Kon Gets A Line

public text v1 · immutable
·published 2008-02-18 22:51 UTC
rendered paste body
        public string getLineFromBrain()
        {
            using (StreamReader brainFile = File.OpenText(BRAIN_FILE))
            {
                // This will add all of the lines in the brain file to an array so we can use them
                ArrayList lines = new ArrayList();
                string line;
                int numberOfLines;

                while ((line = brainFile.ReadLine()) != null)
                    lines.Add(line);

                numberOfLines = lines.Count;

                // Now we need to randomly pick a line and pull a line.

                //Creating a seed from which we can generate random numbers.
                DateTime dateTime = DateTime.Now;
                float mins = dateTime.Minute;
                float secs = dateTime.Second;
                float hour = dateTime.Hour;
                float seed = (secs * mins) + hour;

                Random randnum = new Random(System.Convert.ToInt32(seed));

                int rnd = randnum.Next(numberOfLines);
                string randomLine = (string)lines[rnd];

                brainFile.Close();

                return randomLine;
            }
        }