Earlier quoted context omitted.
The problem isn’t counting the files (the algorithm in the article also counts the files), but that if you determine that you want to use the i th file only after counting all files, you have to iterate over the whole directory again (or over expected half of it) to find that file.
The mechanism is interesting, but I'm not fully understanding the importance. We say it was done this way because a user would appreciate the speedup. The difference is one traversal versus expected one and one-half traversals. How slow was this traversal at the time for this difference to be significant?
What algorithm did Windows XP use to choose your initial user picture?
161–168 of 168 posts
Re: What algorithm did Windows XP use to choose your initial user picture?
#162Man, every post from Raymond Chen regarding Windows internals is like a little Xmas. I wonder whether he has to ask someone for permission before publishing this knowledge, though.
Re: What algorithm did Windows XP use to choose your initial user picture?
#163There's a better way to do this, you use inverse CDF to avoid all the RNG calls. Generate a random number, then skip items until you reach that number: selectRandomFromIteratorOptimized(iterator) { if (!iterator.moveNext()) { return null; } var winner = iterator.current(); var count = 1; while (true) { var u = random_float_open(0.0, 1.0); var skip = (int)Math.Floor(Math.Log(u) / Math.Log(1.0 - (1.0 / (count + 1))));…
Trying to best Windows devs on performance becomes almost comical if you read the comment for the RtlRandomEx:
it is faster than RtlRandom() since it saves one multiplication, one addition and
one modulus operation. This almost doubles the performance since it halves the number of
clocks even on a pipelined Integer Unit such as the P6/ia64 processors i.e. ~ 52% perf gain.
[0]: https://github.com/tongzx/nt5src/blob/daad8a087a4e75422ec96b...
[1]: https://github.com/tongzx/nt5src/blob/daad8a087a4e75422ec96b...Re: What algorithm did Windows XP use to choose your initial user picture?
#164Man, every post from Raymond Chen regarding Windows internals is like a little Xmas. I wonder whether he has to ask someone for permission before publishing this knowledge, though.
Isn't there a guy on youtube that spills tea about the internals of old windows systems? And I suspect their NDAs about XP expired years ago - I don't see much harm in sharing these herbivore algorithms. Very cute post tho.
Re: What algorithm did Windows XP use to choose your initial user picture?
#165Perhaps a math/statistics expert can tell me why that is a bad idea.
Re: What algorithm did Windows XP use to choose your initial user picture?
#166Wouldn't it be even more random (and randomly faster) to break out of the while loop when a winner is found? That way you are not always iterating over the entire list. Perhaps a math/statistics expert can tell me why that is a bad idea.
I didn't get it at first, either, and the Wikipedia article didn't do it for me. This explanation finally got me there: https://florian.github.io/reservoir-sampling/
Re: What algorithm did Windows XP use to choose your initial user picture?
#167Wouldn't it be even more random (and randomly faster) to break out of the while loop when a winner is found? That way you are not always iterating over the entire list. Perhaps a math/statistics expert can tell me why that is a bad idea.
If you break early, then you haven't given items later in the list the chance to be selected. You need to go through the entire list in order for every item to have an equal probability of selection. I didn't get it at first, either, and the Wikipedia article didn't do it for me. This explanation finally got me there: https://florian.github.io/reservoir-sampling/
Re: What algorithm did Windows XP use to choose your initial user picture?
#168Earlier quoted context omitted.
> And it's an old version of the OS anyway. Most modern Windows code was written in 1995. Don't assume for one moment that it isn't in production Win11 today.
You can still get windows 3 directory picker dialogs in obscure places like the ODBC data source utility.