To display a random line from a text file, you should:
- First load all the lines of text into an array (each item in the
array should be a line of text from the file).
- Then you want to generate a random number between 0 and the number
of lines in the text. Use the
Random
class for that.
- And finally you want to print the line in the array using the
generated random number.
Here's the pseudo-code to do the same thing:
Load TextFile
string[] text = Array of lines of text in TextFile
Random rnd = new Random object
int randomLine = New random number generated between 0 and (text.Length - 1)
Print text[randomLine]