Results 1 to 10 of 10

Thread: Read specific line

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Location
    Liverpool, England
    Posts
    155

    Read specific line

    Hello,

    I'm looking at writing a password generator that uses real words. In order to do this I've downloaded a relatively small dictionary text file, about 80K words (600kb), with a word-per-line.

    Now, my problem is what is the best way to pick a word out of this file randomly, preferably with FSO?

    Currently I count the number of lines in the file and use a random number generator to pick a number within the lines-of-file range. This is where I run into problems/issues. I can read each line into an array, and access the random element as required, but is this the best/most efficient way for such a large number of lines?

    Thanks.

  2. #2
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460
    Where did you got this dictionary? I want it too.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Location
    Liverpool, England
    Posts
    155
    There are a few at http://www.puzzlers.org/secure/wordlists/dictinfo.html

    There will probably be loads available if you search the internet.

    Now, back to my question, I can do it using the array method outlined above with FSO and the normal VB open file for input as #1 method. FSO is much slower, but I wanted to use it in case I wanted to use it in ASP in the future. But I suppose there's no problem with making it a dll.

    But is that the best way to do it?

  4. #4
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460
    Why do you want to count how many lines it is every time? Dont you know that?

    Then read Plenderjs tutorial about files (recommended)
    http://209.120.143.185/showthread.ph...specific+lines

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Location
    Liverpool, England
    Posts
    155
    I do know the number of lines, but I can't guarantee new words won't be entered in the future.

    I'll check out the link...

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Location
    Liverpool, England
    Posts
    155
    Unfortunately that didn't help. My existing method isn't unusably slow, but it is sluggish. Since I'm only returning a single word it seems like a long way to do it.

    There must be a better way to do this...

    Cheers.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Location
    Liverpool, England
    Posts
    155
    Ok, sorry to keep banging on about this, but speed is important. Anyway, my new method is to use ADO to open the text file as a recordset, which can then be counted and accessed directly. I'll settle for this at the moment, but if anyone has any suggestions or knows a better way, please let me know.

    Thanks.

  8. #8
    Lively Member Surgeon's Avatar
    Join Date
    Oct 2000
    Posts
    121

    Arrow

    Since the text file is big, even counting the lines would be a waste of time. An you have to count the lines if you want to randomly jump to a line in your file.
    So I have a suggestion :

    Each time the file is updated (added/removed words), count the lines/words and put the result in the first line of the file. For example, a dictionary file would look like this :
    Code:
    17
    abac
    abaca
    abacate
    abacay
    abacinate
    abacination
    abaciscus
    abacist
    aback
    abactinal
    abactinally
    abaction
    abactor
    abaculus
    abacus
    Abadite
    abaff
    since there are 17 words in the file.
    Doing so you'll have 2 advantages :
    1) Whenever you need a random word all you have to do is read the first line (which gives you the number of words), then generate a random number less or equal with the number of words, and jump to that word and retrieve it.
    2) You'd only need to count again (and to update the first line) when your dictionary is updated. And that doesn't happen very often I suppose.

    Cheers

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Location
    Liverpool, England
    Posts
    155
    Cheers, that's a good idea, but it's the jumping to specific line that I don't know how to do...

  10. #10
    Lively Member Surgeon's Avatar
    Join Date
    Oct 2000
    Posts
    121
    well then, import it into any indexed database format you like (say Access). You could make you own text-to-mdb import routine. Then you'd have an indexed dictionary that could be randomly accessed.
    Let me know if I could help you with that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width