News for hackers. Stuff that matters.
Re:What algorithm did Windows XP use to choose your initial ... by Sopel on Thursday September 10, 2026 @09:26AM (#49643355)
I don't see how this is supposedly more efficient than the easier approach of listing all files and choosing a single random number in 1..n
Re:What algorithm did Windows XP use to choose your initial ... by bonzini on Thursday September 10, 2026 @09:30AM (#49643422)
You have to allocate memory and free it.

Interestingly, when reading Raymond Chen's article I thought "reservoir sampling would compare the random number (between 1 and n) to 1, not to n, because that extends more easily to picking more than one element" - and that's what the actual Windows code uses.

Re:What algorithm did Windows XP use to choose your initial ... by Sopel on Thursday September 10, 2026 @01:47PM (#49647655)
yes, you would have to allocate space for up to 100 file paths, but the article says

> it’s more efficient because it reduces the amount of calls into the file system, which is where the bottleneck is

Upon reading it a few times I think the article is alluding to a crappy two-pass solution where you don't store a filename but instead an index into a directory, which is flawed anyway due to being racy.