|
-
Jun 20th, 2002, 05:44 AM
#1
Thread Starter
Addicted Member
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.
-
Jun 20th, 2002, 06:07 AM
#2
Hyperactive Member
Where did you got this dictionary? I want it too.
-
Jun 20th, 2002, 06:16 AM
#3
Thread Starter
Addicted Member
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?
-
Jun 20th, 2002, 06:48 AM
#4
Hyperactive Member
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
-
Jun 20th, 2002, 06:51 AM
#5
Thread Starter
Addicted Member
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...
-
Jun 20th, 2002, 07:27 AM
#6
Thread Starter
Addicted Member
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.
-
Jun 20th, 2002, 07:44 AM
#7
Thread Starter
Addicted Member
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.
-
Jun 20th, 2002, 08:34 AM
#8
Lively Member
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
-
Jun 20th, 2002, 10:37 AM
#9
Thread Starter
Addicted Member
Cheers, that's a good idea, but it's the jumping to specific line that I don't know how to do...
-
Jun 24th, 2002, 07:41 AM
#10
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|