If you know the average string length of each item (or rather the distance between commas) and the size of the file, you can guess at how many items are in the file. Generate a uniformly distributed random integer, and then process the file until you find the item that you choose. If the file ends before you get there, you could either pick a new number (based upon how many items you now know are there), or start at the beginning (distribution is no longer strictly uniform however).
If you are going to pick items over and over, you might treat the problem like the interval of time between soldiers being kicked by horses (exponential waiting times, Poisson problems). You generate an exponential deviate and convert to integer. This is how many positions in the list you travel to get to the next item to pick. When you reach end of list, start at the beginning.
In reply to Re: Pick random item from list of unknown length?
by Anonymous Monk
in thread Pick random item from list of unknown length?
by Cody Fendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |