From Dave Sexton · 1996-03-27 20:44 · #75162 in R25C
On 28 Feb 96 20:19:03, Simon Avery was talking at David
Otton about Tagline manager.
I put my foot in my mouth and mumbled:
Hi Simon Avery,
> If your tagfile is fairly small, it might be better to do the more
> standard method:
> open file.
> fgets until eof, to count the number of lines.
> rewind.
> think of a random number between 0 and num_lines.
> fgets until you reach that line number.
> I's slower, but is more random and does get the first
> line.
Why not try my compromise fro speed:
Keep a file with the total no. of taglines in and the start location of each line. Make sure you re-build this index whenever the tagline file changes. To get a tagline:
Read first longint from index.
Generate random no. between 0 and that no.
fseek through the index to the position
(<rand. no.>*(sizeof (longint)) + sizeof(longint)
(I might be slightly out here, but you get the gist.
read the longint stored there.
open the taglines file.
fseek to the location extracted out of the index et voila!
except for the fact that I've just noticed a bug in my implementation, it works a dream!
.JACK OUT
.ADDITIONAL
... I Just can not resist a little fun along the way. :-)
___ TagBasis V 1.01 (Freeware) With 696 taglines.
--- FMail 0.96â
* Origin: I wish my other computer is a Cray (2:256/155.5)