portable fortune program

Michael Gilfix mgilfix at eecs.tufts.edu
Sun Apr 28 15:28:00 EDT 2002


  Or other simple suggestion:

    1) Have 1 index file that just contains the offsets of the fortunes
       in the other index file and has each entry taking up a fixed amount
       of space.
    2) Get size of the file
    3) Get a random index from file_size / index_size
    4) Seek to fortune in actual file

  That will be really fast as will have no skewing.

                   -- Mike

On Sun, Apr 28 @ 19:17, Jacob Hallen wrote:
> Simple suggestion by me added:
> 
> 1. Get the size of the file.
> 2. Get a random number 0 - size-1.
> 3. Index to this point in the file.
> 4. Iterate back to the nearest previous '%'.
> 5. Print fortune from there.
> 
> This will of course skew the probability of getting printed towards longer
> cookies, but nobody will notice that.

-- 
Michael Gilfix
mgilfix at eecs.tufts.edu

For my gpg public key:
http://www.eecs.tufts.edu/~mgilfix/contact.html





More information about the Python-list mailing list