If you're willing to tradeoff some size in memory, this might be a
little better (note, I often have no idea what I'm doing)-
dim s(-1) As String
s = Split(t1.ReadAll,EndOfLine)
Then use your random array to access the different elements in s, or
perhaps an appropriately named variable.
Better? I have no idea, but please let me know.
Good luck,
Fargo
Ian Piper wrote:
> This is a sort of follow-up question.
>
> For my memorable password routine I thought I would select two words
> from the /usr/share/dict/words file. Because I can't rely on that
> file being available, I decided to take two randomly-generated 100-
> word files out of the words file(step 1 - see below). Then I would
> randomly select a word from each list, process those words to
> randomly assign upper case or numeric values and sandwich them around
> a number. Not world-class security, but reasonable given that it is
> just suggesting passwords for people who can't think one up. I will
> put the final code up here in case anyone else finds it useful.
>
> Anyway. My question is about processing files in the way that I am
> for step 1 above. I have quoted the code for a method below, but I
> know it is really inefficient. I basically want to work through a
> text file with 234936 words (one per line) and write 100 randomly-
> selected words out of that file into another file. The code below
> works, but it is slow (and for some reason always returns "A" as the
> first word in the output file).
>
> If any text processing gurus can suggest how I can make this more
> effective, that would be great.
>
> Thanks,
>
>
> Ian.
> --
>
> ==== code ====
> // This method reads through the words file (234936 lines) and
> randomly chooses 100 words from the list,
> // writing them out into a new file
>
> Dim r As new Random
> dim temp As String
> dim numberarray(100) As Integer
> dim i as Integer
> dim j As Integer
> dim linecounter As Integer
> dim f1 As FolderItem
> dim t1 As TextInputStream
> dim f2 As FolderItem
> dim t2 As TextOutputStream
> dim theWords(100) As String
> dim d As new Date
>
> // create the random number array
> for i = 0 to 99
> // create a new array item
> numberArray(i) = r.InRange(0,234935)
> next
>
> // sort the array in ascending order
> numberarray.sort
>
> // Now we have a sorted list of 100 numbers between 0 and 234935
> // So open up the text file and choose the word at the lines
> represented
> // by each of these numbers
>
> // open the words file
> f1 = Volume(0).Child("Users").Child("Shared").Child("dict").Child
> ("words")
> t1 = f1.OpenAsTextFile
> linecounter = 0
>
> while not t1.EOF
> //read a line from the words file
> temp = t1.ReadLine
> // this is clunky - we have to go through the 100-member array
> for every line in the file
> // There must be a more efficient way of doing this.
> for j = 0 to 99
> // compare the current line in the file with the number at the
> jth position in the number array
> if linecounter = numberarray(j) then
> //write out accepted word to the array
> theWords(j) = temp
> else
> // do nothing
> end if
> next
> linecounter = linecounter + 1
> wend
>
> // Now write the word list out as a file - give it a timestamped
> filename
> f2 =Volume(0).Child("Users").Child("Shared").Child("dict").Child
> ("words" + str(d.Hour) + str(d.Minute) + str(d.Second))
> t2 = f2.CreateTextFile
> for i = 0 to 99
> // work through theWords array, writing each item out to a new
> line in the file
> t2.WriteLine(theWords(i))
> next
> t2.Close
> ==== code ====
>
>
>
>
> _______________________________________________
>
>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
|