Pascal is good for a lot, but it is notoriously weak on text data manipulation.
If you know Pascal, you can pick up Basic really quickly.
The first trick is to find an application of Basic for your PC. Check out justbasic.com, which has a free, simple, pretty direct app. Did I mention free?
As I see it, the structure is this:
Open a file, pointing to your initial text file. Let’s say it is “One Two Three Four.”
Input data from that file, one character at a time. Buffer the characters, and, when you hit a space (or the end-of-file) increment the word-counter, dump the buffer into the word array, and reset the letter counter. Now you have the following data:
WORDS(n) where WORDS(1) = “One”, WORDS(2) = “Two,” etc.
Pick a random number, j, from one to n. If j=3, the WORDS(j) = “Three.”
Now you’ve got to keep track of the numbers available. In this example, I want to remove “3” from the controlling array, so that the next random choice can only be among 1, 2, and 4. I’m too lazy to go into that right now; it involves a second array of NUMBERS, where you remove the chosen element from the array, and close up the gap.
Keep doing this till you exhaust the array…
If I’m talking Martian, I apologize. All of this is really about the limits of my programming skill, but if you’ve had Pascal classes, you’re probably following or even ahead a bit.
(I don’t actually have Justbasic – but I think I need to get it! It looks pretty keen, and even does GUI apps. And it’s free!)