What if you don't know how many lines are in the original source? What if there are only two lines, and you write the first into line 1000. Now you have a 1000 line text file with loads of wasted space, you can't do a second pass to cleanup the empty lines because who's to say there aren't blank lines in the source?
Doing this in memory will always be faster, you are doubling the disk IO (which is the slowest part), especially since Acid doesn't specify *what* he wants to do with the text once it's randomized.
@Acid how big is quite big? 50MB? 1GB?
Easy peasy lemon squezy, dequadin.... let me tell you.
What if you don't know how many lines are in the original source?
easy.
most languages have a command that counts the number of lines in a text file *instantly*
mine is EOF (End of File) which returns a value with the amount of lines.
What if there are only two lines, and you write the first into line 1000.
easy.
1st iteration it will random between 0 and 1 - so line 1.
2nd iteration it will random between 0 and 2 - so it can randomize before, OR, after - so it will still be random even if there are only a *few* lines
55th iteration it will random between 0 and 55
1055th iteration it will random between 0 and 1055
So, It won't write into line 1000 if it hasn't reached the 1000th iteration - you use the iteration as the max value it can random to.
Now you have a 1000 line text file with loads of wasted space, you can't do a second pass to cleanup the empty lines because who's to say there aren't blank lines in the source?
no second pass needed as explained
Doing this in memory will always be faster, you are doubling the disk IO (which is the slowest part), especially since Acid doesn't specify *what* he wants to do with the text once it's randomized.
well loading 2GB into memory might take long too, and what if the user only has 512mb ram?
Memory is usually better, but the disk based one will work on any PC - even if it only has 256mb ram