News for hackers. Stuff that matters.
Re:What algorithm did Windows XP use to choose your initial ... by mawadev on Thursday September 10, 2026 @06:39AM (#49641429)
That is a case I only become aware of when I read blogs like this. Technically I could solve it the same way, but these days you have so many tasks on your desk, you don't think about the problem and implications at all and that awareness/discipline is drowned in the noise/unlearned over time.

If someone only gave me 2 minutes for this, because they think it is very simple (as always), I'd have done a count of files of a specific pattern in the directory and then picked a random index, very naive and quick and dirty programming, no sampling at all, just to avoid discussions why it takes so long with people who don't want to hear it.

This reminds me of when I did a lot of C#, Java, JS, Python in my life, filling maps of strings and objects until I started with zig and noticed how expensive and complicated strings and data structure allocations can be. It kind of blew my mind how much memory and computation we waste when we try to get stuff done as fast as possible because of budget/time constraints.

Re:What algorithm did Windows XP use to choose your initial ... by cabirum on Thursday September 10, 2026 @10:19AM (#49644155)
Counterexample: desktop icon layout in quadratic time: https://randomascii.wordpress.com/2021/02/16/arranging-invis...

Its not like windows is the pinnacle of software craftsmanship.

Re:What algorithm did Windows XP use to choose your initial ... by kevin_thibedeau on Thursday September 10, 2026 @02:28PM (#49648235)
I'd bet this bug also shows up in Vista file explorer with auto arrange disabled. Nobody will ever need more than 100 icons on their 800x600 workstation. Ship it.
Re:What algorithm did Windows XP use to choose your initial ... by Aurornis on Thursday September 10, 2026 @01:10PM (#49647090)
Two things that have helped me with quickly recognizing these situations:

Programming for MCUs. Less so today when multi-hundred MHz MCUs are cheap, but even several years ago there were a lot of products where you needed to use the cheapest MCU and everything it did had to be optimized to avoid stalls and edge cases.

Second is doing LeetCode problems for fun/practice. This will elicit a groan from a lot of people, but the algorithms and pathological edge cases you learn really do change your thinking. The most interesting ones are the hard problems where they’ve added some hidden test case that causes naive solutions and algorithms to blow up. You start thinking on high alert for edge cases and Big O problems. It’s more fun when you’re doing it to learn on your own than for forced interview prep.

Re:What algorithm did Windows XP use to choose your initial ... by CamperBob2 on Thursday September 10, 2026 @01:21PM (#49647260)
How many user pictures are there to choose from, though? This is a nice, elegant way to sample from the set, but the nature, size, and frequency of the problem don't justify more than five or ten seconds' or thought and one or two minutes of coding.
Re:What algorithm did Windows XP use to choose your initial ... by dwattttt on Thursday September 10, 2026 @01:34PM (#49647469)
But multiplied by the number of times it'll run on the planet, and you have a surprisingly big impact.
Re:What algorithm did Windows XP use to choose your initial ... by mawadev on Thursday September 10, 2026 @01:50PM (#49647713)
Exactly this, if you count the amount of time the windows 11 context menu needs to pop up and then the second click to get to the old context menu across the entire globe for a month, you would get an insane amount of time and cycles wasted
Re:What algorithm did Windows XP use to choose your initial ... by CamperBob2 on Thursday September 10, 2026 @03:57PM (#49649398)
I guess I'd do it once, the slow and easy way, and cache the result. But that's just me.
Re:What algorithm did Windows XP use to choose your initial ... by dwattttt on Thursday September 10, 2026 @04:55PM (#49650042)
The billions of times aren't repeated times for the same person, it's because it's been done for the first time billions of times. This is the "choose a user's initial profile picture". They're not randomly changing it.
Re:What algorithm did Windows XP use to choose your initial ... by dsego on Thursday September 10, 2026 @08:21AM (#49642572)
Why doesn't it return on the first match?
Re:What algorithm did Windows XP use to choose your initial ... by yoz-y on Thursday September 10, 2026 @08:33AM (#49642714)
Because it would always return the first match in that case.

You still need to see all of the items once.

Imagine you have 2 items.

First one has 100% chance to be selected. So it does. Then the second has 50% chance to be selected. If it isn’t you effectively chosen the first one and have 50/50 chance to return either.

Now you add a third item. There is 50/50 chance of having either selected. And 1/3 chance of replacing the selection with the new one. Resulting in a 1/3 chance of selecting any of the three. (Because 1/2-1/6 = 1/3) 1/6 because there is 50% chance you will “steal” the selection.

Re:What algorithm did Windows XP use to choose your initial ... by Elte on Thursday September 10, 2026 @09:07AM (#49643118)
Thank you for writing this out, I didn't quite get what was going on at first. But then, to formalize the recursion from your example: let's assume we're at item n in the iterator, and at that point we've selected a winner from the previous n-1 items with equal probability, i.e. each item had a 1/(n-1) chance of being selected. The probability that item n will override it is 1/n. The probability that the old winner will remain selected is thus (n-1)/n. That means that the old winner remains selected with probability 1/(n-1) * (n-1)/n, which cancels out to 1/n, so each item is indeed selected with equal probability in the end.
Re:What algorithm did Windows XP use to choose your initial ... by Anon_troll on Thursday September 10, 2026 @10:21AM (#49644187)
An alternative wording for the same idea:

If you are at picture 1, you have 100% chance of selecting it as the current winner.

If you are at picture 2, you have 1/2 chance of selecting it as the current winner, or 1/2 chance of keeping the previous fairly selected winner.

At picture 3, 1/3 chance of picking it, or 2/3 chance of retaining the previous fairly-selected winner. There are two of them, so 1/3 chance of each.

At picture n, you have a 1/n chance of picking it, or an (n-1)/n chance of retaining the previous fairly-selected winner. There are n-1 previous pictures, so all of them have had 1/n chance of being picked.

At every single step, there is the invariant of all pictures being considered that far having had an equal chance of being selected, and the next step always retains the invariant.

Re:What algorithm did Windows XP use to choose your initial ... by matsemann on Thursday September 10, 2026 @11:43AM (#49645678)
This feels very analogous to the three doors puzzle.
Re:What algorithm did Windows XP use to choose your initial ... by dsego on Thursday September 10, 2026 @09:56AM (#49643791)
Oh, I understand, should've examined more carefully, the count starts at 0 and increments, so random is not from the total but from the elements counted so far.
Re:What algorithm did Windows XP use to choose your initial ... by quentinkent1 on Thursday September 10, 2026 @08:31AM (#49642684)
exactly. There is something wrong with the code snippet.
Re:What algorithm did Windows XP use to choose your initial ... by arpadav on Thursday September 10, 2026 @08:53AM (#49642945)
No there is not. First element is defacto winner, but you still have to loop through the rest with 1/n chance of being selected to fully give each element a chance of winner selection
Re:What algorithm did Windows XP use to choose your initial ... by fschuett on Thursday September 10, 2026 @09:46AM (#49643653)
Yeah I think the "wrong feeling" is just that this could, in theory, be O(1) with something like:

  pics[Math.random() * len(pics)]
... assuming that random() gives you a number from 0..1 - but that's why it feels "wrong".
Re:What algorithm did Windows XP use to choose your initial ... by Anon_troll on Thursday September 10, 2026 @10:12AM (#49644022)
The len(pics) can be O(n), especially if iterators are used like here. Also, an O(1) lookup would require a previous O(n) pass over the data anyway.

The picture selection algorithm's kind of single-pass iterator usage might have been more performant back in the XP days, as it avoids possibly expensive operations.

Modern CPU/other optimizations might make a multi-pass approach more performant due to better memory locality or other factors.

Re:What algorithm did Windows XP use to choose your initial ... by akdev1l on Thursday September 10, 2026 @10:06AM (#49643931)
len(pics) either already knows about the length or it needs to count so it’s O(n)
Re:What algorithm did Windows XP use to choose your initial ... by kleiba2 on Thursday September 10, 2026 @08:54AM (#49642960)
On count == 1, the winner gets set to the first element, true. But the function does not return yet! So the value might get overwritten during the remainder of the for-loop.
Re:What algorithm did Windows XP use to choose your initial ... by dsego on Thursday September 10, 2026 @09:57AM (#49643805)
I re-examined it, the count changes, that's why it works. The random is not between 1 and total, it's between 1 and current count.
Re:What algorithm did Windows XP use to choose your initial ... by lyorig on Thursday September 10, 2026 @06:57AM (#49641591)
Man, 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 ... by alex_suzuki on Thursday September 10, 2026 @07:43AM (#49642075)
I also wonder what his thoughts on “modern Windows” are
Re:What algorithm did Windows XP use to choose your initial ... by dyllon on Thursday September 10, 2026 @07:56AM (#49642257)
His silence speaks a thousand words.
Re:What algorithm did Windows XP use to choose your initial ... by bigstrat2003 on Thursday September 10, 2026 @09:42AM (#49643601)
Yeah I agree. Mr. Chen strikes me as too professional to put his employer on blast like that, but he's likely not a fan.
Re:What algorithm did Windows XP use to choose your initial ... by jasomill on Thursday September 10, 2026 @10:36PM (#49652903)
I imagine he's fine with it in terms of job satisfaction at the very least, as far as I can tell his areas of expertise are shell and related COM internals, and he clearly takes pride in the nuances of cleaning up other peoples' messes, and if there are two things that have remained constant in Windows programming over the past 30 years, it's COM and messes.
Re:What algorithm did Windows XP use to choose your initial ... by 98codes on Thursday September 10, 2026 @12:26PM (#49646393)
It's not as if he's stopped working on Windows since 2000.
Re:What algorithm did Windows XP use to choose your initial ... by Hydraulix989 on Thursday September 10, 2026 @09:21AM (#49643295)
Easier for a guy like him to be forgiven than to ask permission.

Being tenured and one of the top engineers in your company with a very proven track record gives you quite a bit more freedom.

Re:What algorithm did Windows XP use to choose your initial ... by xp84 on Thursday September 10, 2026 @12:39PM (#49646581)
Yeah - he's more likely the guy that would be giving that kind of permission to someone more junior.
Re:What algorithm did Windows XP use to choose your initial ... by fred_is_fred on Thursday September 10, 2026 @10:22AM (#49644196)
If you ask for permission on something like this the answer is always no.
Re:What algorithm did Windows XP use to choose your initial ... by cloudfudge on Thursday September 10, 2026 @11:15AM (#49645201)
It's been many years since I talked to him, but he's an extremely by-the-book guy, so I'm sure he has a process for clearing everything he writes. His reputation does probably provide him a lot of leeway, though. He also has a queue of oldnewthing articles about a mile long and we could probably get years' worth of articles after his death if they let them run.
Re:What algorithm did Windows XP use to choose your initial ... by petya415 on Thursday September 10, 2026 @04:56PM (#49650063)
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 ... by aqfamnzc on Thursday September 10, 2026 @05:16PM (#49650266)
Dave Plummer?
Re:What algorithm did Windows XP use to choose your initial ... by reddalo on Friday September 11, 2026 @06:39AM (#49656173)
I used to follow him, but then I've read some controversial news about him...
Re:What algorithm did Windows XP use to choose your initial ... by jasomill on Thursday September 10, 2026 @10:54PM (#49653012)
Forget YouTube. Google "windows xp source code leaks" and one of the top hits is a six-year old GitHub repo.

Which sort of makes sense. I'm not sure technical trade secrets have ever played much of a role in Microsoft's success.

With or without source code, programmers have been digging at the internals of Microsoft OSes for fun and profit since the DOS days, and Microsoft has always seemed to recognize that developers and customers relying on the undocumented nuances of their products benefits them far more than understanding them benefits their competitors.

Re:What algorithm did Windows XP use to choose your initial ... by impoppy on Thursday September 10, 2026 @07:56AM (#49642264)
>Raymond has been involved in the evolution of Windows for more than 30 years. He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.
Re:What algorithm did Windows XP use to choose your initial ... by carrja99 on Thursday September 10, 2026 @08:00AM (#49642322)
That made me chuckle too. No utility, but I did find it interesting.
Re:What algorithm did Windows XP use to choose your initial ... by VCFundedGenYer on Thursday September 10, 2026 @11:52AM (#49645833)
A true Microsoft drone to the end.
Re:What algorithm did Windows XP use to choose your initial ... by cgio on Thursday September 10, 2026 @06:12AM (#49641205)
The times when people spent an extra brain cycle to avoid billions of second passes.
Re:What algorithm did Windows XP use to choose your initial ... by ape4 on Thursday September 10, 2026 @08:05AM (#49642371)
It somewhat odd that systems don't have a call to tell you how many files are in a folder.
Re:What algorithm did Windows XP use to choose your initial ... by ygra on Thursday September 10, 2026 @08:20AM (#49642553)
Either that call would have to do the same (i.e., walking the files and counting), or you'd need some additional metadata in the directory entry to store how many files there are, requiring additional storage accesses for adding and removing files. Adding to that that both FAT32 and NTFS are quite old and had to run on older hardware. Cycles and disk accesses are not free.

On top of that, how often is it necessary to efficiently know the number of files in a directory while at the same time not caring about the files enough to list or display them? This algorithm is a special case where you could use the count of using a bit simpler code that ultimately would have the same file system API calls (since you cannot tell the FS to give you file #37 from that directory, so you'd have to use FindNextFile 37 times anyway, just like the sampling algorithm).

Re:What algorithm did Windows XP use to choose your initial ... by chungy on Thursday September 10, 2026 @10:12AM (#49644026)
Not that it counters any point you're making, but ZFS displays the number of contained entries of a directory in the directory's size field; mind that . and .. are included, so you usually need to subtract 2 to get the count you actually want. I do find it useful sometimes to know the count without getting the listing; the former is a very inexpensive operation (since ZFS is keeping track of metadata like you suggested), the latter is expensive, potentially extremely with hundreds of thousands or more of entries.

This is more-or-less unique to ZFS. Other file systems even on Linux and FreeBSD generally don't provide this behavior.

Re:What algorithm did Windows XP use to choose your initial ... by wongarsu on Thursday September 10, 2026 @10:17AM (#49644132)
ZFS being a copy-on-write fs probably made the relative cost of that feature much cheaper
Re:What algorithm did Windows XP use to choose your initial ... by tredre3 on Thursday September 10, 2026 @01:38PM (#49647529)
> or you'd need some additional metadata in the directory entry to store how many files there are, requiring additional storage accesses for adding and removing files.

Most unix filesystems use inodes. inodes have the same format whether they represent a file or directory. So directory have a (usually unused) size member. NTFS doesn't use inodes, but the records in the MFT work the same way.

When adding or removing a file from a directory, you have to update the modification time of the folder, so you have to rewrite the entire inode anyway. Updating the size/file count at the same time would be free.

In my opinion the likely reason why file count isn't tracked is a lot more pedestrian: It wasn't tracked initially and we can never add it to existing file systems because the metadata would get out of sync if the FS was mounted on a kernel with no count support.

I base this assumption on the fact that many modern file systems do indeed keep track of the count.

Re:What algorithm did Windows XP use to choose your initial ... by eventualcomp on Thursday September 10, 2026 @08:17AM (#49642518)
I feel like there would either be too many locks or too much contention on something like /var/log or /tmp if that API was ever exposed to userspace.
Re:What algorithm did Windows XP use to choose your initial ... by conorcleary on Thursday September 10, 2026 @08:07AM (#49642403)
just have it count how many times del cmd runs successfully /s
Re:What algorithm did Windows XP use to choose your initial ... by saagarjha on Thursday September 10, 2026 @08:13AM (#49642466)
Claude, is that you?
Re:What algorithm did Windows XP use to choose your initial ... by xnickb on Thursday September 10, 2026 @08:26AM (#49642635)
The good old Aqua Regia test.
Re:What algorithm did Windows XP use to choose your initial ... by EMIRELADERO on Thursday September 10, 2026 @07:55AM (#49642241)
For those interested, here's the actual code Chen talks about: https://github.com/tongzx/nt5src/blob/daad8a087a4e75422ec96b...
Re:What algorithm did Windows XP use to choose your initial ... by ycuser2 on Thursday September 10, 2026 @08:04AM (#49642359)
Didn't know that NT5 source is available for the public. Why Microsoft does not ban/delete it on GitHub?
Re:What algorithm did Windows XP use to choose your initial ... by lr0 on Thursday September 10, 2026 @08:50AM (#49642919)
They are usually deleted, maybe this one hasn't got popular enough yet.
Re:What algorithm did Windows XP use to choose your initial ... by Philpax on Thursday September 10, 2026 @09:01AM (#49643042)
It's been around for six years; at this point, I imagine any damage it could have done has been done already.
Re:What algorithm did Windows XP use to choose your initial ... by sph on Thursday September 10, 2026 @08:51AM (#49642925)
It'll pop up elsewhere so might as well keep it online on their servers. And it's an old version of the OS anyway.

If it were the Windows 11 source, it'd get nuked immediately

Re:What algorithm did Windows XP use to choose your initial ... by VCFundedGenYer on Thursday September 10, 2026 @11:52AM (#49645828)
> 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.

Re:What algorithm did Windows XP use to choose your initial ... by kevin_thibedeau on Thursday September 10, 2026 @02:38PM (#49648398)
You can still get windows 3 directory picker dialogs in obscure places like the ODBC data source utility.
Re:What algorithm did Windows XP use to choose your initial ... by Sophira on Thursday September 10, 2026 @06:29PM (#49651004)
You can even still get error messages referencing the CONFIG.SYS file, which hasn't been relevant for well over two decades at this point: https://www.reddit.com/r/sysadmin/comments/1wctbf3/throwback...
Re:What algorithm did Windows XP use to choose your initial ... by downrightmike on Thursday September 10, 2026 @07:11PM (#49651383)
Why remove things, storage is only getting cheaper /s
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.

Re:What algorithm did Windows XP use to choose your initial ... by misiek08 on Wednesday September 23, 2026 @10:21AM (#49816631)
Thanks for that. Algorithm in article looks like always choosing first picture and I was curious what magic is there behind.
Re:What algorithm did Windows XP use to choose your initial ... by jasonvorhe on Thursday September 10, 2026 @05:49AM (#49641045)
A couple of screenshots would've been useful for the post-millennial generations that never got to see the "beauty" (cough) of XP.
Re:What algorithm did Windows XP use to choose your initial ... by moritzwarhier on Thursday September 10, 2026 @06:01AM (#49641130)
Here's a blog post from 2003 with beautiful pictures.

https://jakeludington.com/2003/12/17/create_your_own_windows...

Re:What algorithm did Windows XP use to choose your initial ... by seba_dos1 on Thursday September 10, 2026 @10:18AM (#49644147)
These pictures are so compressed they depict color rasterization artifacts more than the Luna UI style.
Re:What algorithm did Windows XP use to choose your initial ... by Maken on Thursday September 10, 2026 @06:14AM (#49641219)
XP is Microsoft's prettiest OS by far.
Re:What algorithm did Windows XP use to choose your initial ... by mrweasel on Thursday September 10, 2026 @06:25AM (#49641307)
That's a matter of taste, but for many it was the Windows they used first and/or spend the most time on and there's a lot of love for that reason alone. I never used XP all that much, but I always changed the theme to the Windows 2000 look. I really didn't like the default, it looked unprofessional and clunky in my eyes. Upon release XP was also pretty universally mocked as a Fisher Price-like UI.

To me Windows 95/NT 4 is still the gold standard in Windows UI. It's certainly not the prettiest, that would be Windows 2000, but it was easy to use, easy to navigate and efficient with space.

Re:What algorithm did Windows XP use to choose your initial ... by agumonkey on Thursday September 10, 2026 @07:35AM (#49641966)
win2k was peak for me. lean, functional, just a pinch of glitter here and there (short fade-ins). it was on par with the amazing stability brought by nt5 kernel.

i kinda miss xp at a cultural level since it was a bit the end of that computing culture cycle (after that apple started to dominate and ubuiquitous computing influenced desktop ui)

Re:What algorithm did Windows XP use to choose your initial ... by Intermernet on Thursday September 10, 2026 @08:08AM (#49642409)
"after that apple started to dominate"

When did Apple dominate? I'm not trying to hate on Apple here, but there's this weird belief that Apple have had a lead in personal computer OS market share at some point in the last few decades, and it isn't really true since about 1984.

You can argue that they should dominate, but that doesn't seem to have happened.

Re:What algorithm did Windows XP use to choose your initial ... by 2muchcoffeeman on Thursday September 10, 2026 @09:16AM (#49643229)
Maybe they mean culturally.
Re:What algorithm did Windows XP use to choose your initial ... by agumonkey on Thursday September 10, 2026 @10:44AM (#49644621)
The mac os x and iphone era dictated UI and UX for a while. I wasn't clear that I wasn't talking about market share.
Re:What algorithm did Windows XP use to choose your initial ... by unregistereddev on Thursday September 10, 2026 @10:44AM (#49644612)
I remember Apple products being the realm of graphics designers, videographers, and other art professionals back in the XP days. I thought they went mainstream later, as Windows Vista coincided with the iPhone release.
Re:What algorithm did Windows XP use to choose your initial ... by afzalive on Thursday September 10, 2026 @06:58AM (#49641600)
Took me years to like Windows XP. Hated the new start menu. I always kept installing Windows 2000 (or ME, probably because it could use Windows 98 drivers but look like Windows 2000).

I eventually got used to it and ended up liking it.

Re:What algorithm did Windows XP use to choose your initial ... by stingraycharles on Thursday September 10, 2026 @07:41AM (#49642050)
It was at this moment I realized that people are talking about liking the non-classic-look XP. I always immediately put things in classic look, no grouped windows, etc.
Re:What algorithm did Windows XP use to choose your initial ... by alex_suzuki on Thursday September 10, 2026 @07:44AM (#49642100)
IIRC correctly, XP’s stability greatly increased after Service Pack 2 was published.
Re:What algorithm did Windows XP use to choose your initial ... by gschizas on Thursday September 10, 2026 @10:14AM (#49644062)
XP Service Pack 2 was in essence a different OS.
Re:What algorithm did Windows XP use to choose your initial ... by deltoidmaximus on Thursday September 10, 2026 @08:29AM (#49642670)
I always ran it with the 2000 style theme. That said XP offered me nothing over 2000 so 2000 is what I ran on my main machine since it used less ram but did all the same things, often a bit faster.

For awhile I ran XP 64-bit though, that did do one thing 2000 couldn't do.

Re:What algorithm did Windows XP use to choose your initial ... by Maken on Thursday September 10, 2026 @06:43AM (#49641461)
The first Windows I used was 98, and I sure didn't miss the blocky grey menus nor the pixelated icons. Maybe it was Fisher Price-ish but the new rounded buttons and borders were way more appealing to me.
Re:What algorithm did Windows XP use to choose your initial ... by TazeTSchnitzel on Thursday September 10, 2026 @06:33AM (#49641380)
The "Windows Classic" look on XP is exceptionally ugly, because those 3D-rendered icons just do not belong on a Windows 2000-style grey background for menus or buttons. (I have recently had to test both these OSes in VMs…)
Re:What algorithm did Windows XP use to choose your initial ... by mrweasel on Thursday September 10, 2026 @06:39AM (#49641430)
That is true, it looked completely off, as if no one really bothered to tests it and make it look nice. It got rid of the horrible window decoration of the default theme, but the start menu looked terrible.
Re:What algorithm did Windows XP use to choose your initial ... by pndy on Thursday September 10, 2026 @08:58AM (#49643000)
Of course that's a matter of taste but Luna interface/theme made whole XP being more appealing to ordinary people - especially with these task-oriented elements. On the other hand, "classic" widgets had that strong bare-bone technical and functional look that made whole system scarier to some degree.

I had tons of "Visual Styles" back then and in the last XP days I opted for grayish Royal or Royale. It's such shame that MS has abandoned Watercolor theme - that was a middle ground: interface was updated and yet, still similar to classic design. And it was even in some elements flat before that style become a dominant. Luckily we're slowly moving away from that and I won't be missing it.

Re:What algorithm did Windows XP use to choose your initial ... by bsoqk on Thursday September 10, 2026 @07:58AM (#49642286)
https://devblogs.microsoft.com/oldnewthing/20040331-00/?p=39...

>During the Luna studies, that people’s reaction to Luna was often, “Wow this would be a great UI for X,” where X was “my dad” or “my employees” or “my daughter”. People didn’t look at it as the UI for themselves; rather, they thought it was a great UI for somebody else.

(Luna is the name of the default look of Windows XP)

Re:What algorithm did Windows XP use to choose your initial ... by delta_p_delta_x on Thursday September 10, 2026 @07:12AM (#49641719)
I feel Vista was by far the best. 7 simplified it a bit, but that Start orb and black taskbar on Vista, man, that was glorious.
Re:What algorithm did Windows XP use to choose your initial ... by kasabali on Thursday September 10, 2026 @02:13PM (#49648040)
IMO Aero parts looked phenomenal but older Win32 parts like toolbars etc. didn't fit and looked odd
Re:What algorithm did Windows XP use to choose your initial ... by YPPH on Thursday September 10, 2026 @06:55AM (#49641574)
I found each of 2000, XP, and 7 to be excellent in its own unique way. I'd be happy with any of them. But it also felt exciting to upgrade.

It's all been downhill from there as far as UX goes.

Re:What algorithm did Windows XP use to choose your initial ... by meerita on Thursday September 10, 2026 @07:40AM (#49642035)
Ehem... nothing beats the beauty and simplicity of Win 95 :)
Re:What algorithm did Windows XP use to choose your initial ... by edoceo on Thursday September 10, 2026 @08:56AM (#49642976)
Didn't that design appear first in 3.51?
Re:What algorithm did Windows XP use to choose your initial ... by TheAmazingRace on Thursday September 10, 2026 @10:57AM (#49644857)
Only if you install the Shell Technology Preview from Microsoft. NT 3.51 came with the classic Win 3.x look and feel as well as Program Manager.
Re:What algorithm did Windows XP use to choose your initial ... by edoceo on Thursday September 10, 2026 @11:47AM (#49645747)
Yea, it was 4.0, oops
Re:What algorithm did Windows XP use to choose your initial ... by fractal618 on Thursday September 10, 2026 @07:54AM (#49642227)
I like the installation music :-)
Re:What algorithm did Windows XP use to choose your initial ... by rzzzt on Thursday September 10, 2026 @08:28AM (#49642665)
"Welcome to Windows 98" with the church bell and sick bass intro can never be beaten. It's cut short unfortunately.
Re:What algorithm did Windows XP use to choose your initial ... by amiga-workbench on Thursday September 10, 2026 @07:02AM (#49641634)
Perhaps with the Zune theme installed.
Re:What algorithm did Windows XP use to choose your initial ... by sunaookami on Thursday September 10, 2026 @06:41AM (#49641439)
You mean 7 ;)
Re:What algorithm did Windows XP use to choose your initial ... by medwards666 on Thursday September 10, 2026 @06:55AM (#49641572)
Windows 7 was certainly pretty, but I still think that W2000 was peak Windows UI (and I've been around since Windows 2.0)
Re:What algorithm did Windows XP use to choose your initial ... by Maken on Thursday September 10, 2026 @06:45AM (#49641490)
Windows 7 fixed Vista a bit, but the Aero windows were never pretty and the non-Aero decorations were painfully obvious a placeholder.
Re:What algorithm did Windows XP use to choose your initial ... by sunaookami on Thursday September 10, 2026 @02:45PM (#49648483)
Aero was pretty though.
Re:What algorithm did Windows XP use to choose your initial ... by ksncksndsh on Thursday September 10, 2026 @11:11AM (#49645137)
That’s Vista. And there’s no contest whatsoever. They’ve never been able to again achieve the perfect balance of elegance and functionality that Vista’s UI had.

Its Vista. Like it or hate it. It’s Vista

Re:What algorithm did Windows XP use to choose your initial ... by CalRobert on Thursday September 10, 2026 @06:07AM (#49641175)
I thought it looked great :-/
Re:What algorithm did Windows XP use to choose your initial ... by PalmPilotProMax on Thursday September 10, 2026 @06:25AM (#49641304)
I don't see how that's relevant? Article is about the RNG implementation, it doesn't matter what the profile pictures are.
Re:What algorithm did Windows XP use to choose your initial ... by lirolero on Thursday September 10, 2026 @07:24AM (#49641855)
> I don't see how that's relevant?

nobody cares

Re:What algorithm did Windows XP use to choose your initial ... by KellyCriterion on Thursday September 10, 2026 @07:09AM (#49641693)
Why they made it that complex?

A simple rand/mod based on first character of username should be sufficient?

Re:What algorithm did Windows XP use to choose your initial ... by nkrisc on Thursday September 10, 2026 @08:07AM (#49642398)
So users Adam, Anne and Archie all have the same profile image?
Re:What algorithm did Windows XP use to choose your initial ... by KellyCriterion on Thursday September 10, 2026 @09:26AM (#49643365)
OK - then use the first two characters :-D
Re:What algorithm did Windows XP use to choose your initial ... by sltkr on Thursday September 10, 2026 @04:18PM (#49649633)
So Adam, Adele, and Adrian all have the same profile image?
Re:What algorithm did Windows XP use to choose your initial ... by KellyCriterion on Friday September 11, 2026 @03:58AM (#49654972)
The the thing is:Most Adams/Adeles/Adrians wouldnt even notice
Re:What algorithm did Windows XP use to choose your initial ... by lentil_soup on Thursday September 10, 2026 @07:16AM (#49641766)
because you don't know the number of images before running the code so no number to do the mod part
Re:What algorithm did Windows XP use to choose your initial ... by moffkalast on Thursday September 10, 2026 @07:43AM (#49642083)
Why wouldn't you know that? It's a set of preloaded stock photos, it's always gonna be the same number.
Re:What algorithm did Windows XP use to choose your initial ... by elgertam on Thursday September 10, 2026 @08:08AM (#49642412)
On initial install, sure. But user accounts can also be created at arbitrary times. The user may have changed the set of photos in the intervening time and might even be editing the directory during profile creation.
Re:What algorithm did Windows XP use to choose your initial ... by throwaway219450 on Thursday September 10, 2026 @12:37PM (#49646558)
I thought the same thing, and then wondered if this must be an enterprise problem, because what home user adds loads of icons - so many that IO becomes a concern - and also wants them to be randomly assigned to other family members?

But then it occurred to me that XP was of an era when you would absolutely spend an afternoon downloading some megapack of 10000 cool user icons.

Re:What algorithm did Windows XP use to choose your initial ... by bombcar on Thursday September 10, 2026 @08:06AM (#49642389)
It’s a directory. You could add pictures to it, and we did in our image layout (mainly for fun, but they wanted the logo as one).
Re:What algorithm did Windows XP use to choose your initial ... by herywort on Thursday September 10, 2026 @07:54AM (#49642225)
> As a final safety check, the code stops after sampling 100 pictures. This avoids pathological behavior if somebody puts a million files in the Default Pictures directory
Re:What algorithm did Windows XP use to choose your initial ... by consp on Thursday September 10, 2026 @07:52AM (#49642209)
At compile time of when the pr department decided to change it?
Re:What algorithm did Windows XP use to choose your initial ... by stephenlf on Thursday September 10, 2026 @08:12AM (#49642454)
How is that simpler?
Re:What algorithm did Windows XP use to choose your initial ... by KellyCriterion on Thursday September 10, 2026 @09:27AM (#49643374)
because its a built-in one-liner call then?
Re:What algorithm did Windows XP use to choose your initial ... by bombcar on Thursday September 10, 2026 @06:28AM (#49641336)
Does it also check existing users so you don't match one?
Re:What algorithm did Windows XP use to choose your initial ... by reddalo on Thursday September 10, 2026 @08:36AM (#49642753)
Re:What algorithm did Windows XP use to choose your initial ... by bhaney on Thursday September 10, 2026 @06:02AM (#49641137)
100 seems like a very unnecessarily low limit, even for the time
Re:What algorithm did Windows XP use to choose your initial ... by daveoc64 on Thursday September 10, 2026 @06:16AM (#49641228)
It's well above the number of images that were in the applicable folder by default, so seems pretty appropriate to me.
Re:What algorithm did Windows XP use to choose your initial ... by moritzwarhier on Thursday September 10, 2026 @06:03AM (#49641144)
Some say the Admin account defaulted to a chessboard.

I think it's true, but not sure if I'm just falling victim to false memories... help?

Re:What algorithm did Windows XP use to choose your initial ... by TazeTSchnitzel on Thursday September 10, 2026 @06:35AM (#49641395)
The account named "Administrator" that Windows created for you always had the chess piece.
Re:What algorithm did Windows XP use to choose your initial ... by bhaney on Thursday September 10, 2026 @06:30AM (#49641353)
There's no way my memory of this is reliable anymore, but I also remember my administrator account being chess pieces (and my user account being an orange fish).
Re:What algorithm did Windows XP use to choose your initial ... by bombcar on Thursday September 10, 2026 @06:27AM (#49641319)
It might be that the randomization code was bypassed in some cases - like creating an account in safe boot mode or similar.
Re:What algorithm did Windows XP use to choose your initial ... by xx_ns on Thursday September 10, 2026 @06:33AM (#49641384)
It makes sense. The chess piece is the first profile picture in the list.
Re:What algorithm did Windows XP use to choose your initial ... by abhinavk on Thursday September 10, 2026 @06:23AM (#49641283)
I remember it like that too. Or is it Mandela effect?
Re:What algorithm did Windows XP use to choose your initial ... by NitpickLawyer on Thursday September 10, 2026 @06:29AM (#49641348)
The Magnus effect? :)
Re:What algorithm did Windows XP use to choose your initial ... by Aditya_0315 on Thursday September 10, 2026 @08:26AM (#49642625)
What is amazing is the amount of consideration given to an issue which would escape the majority of users. It is surprising how complex an apparently easy process turns out when considering certain special cases.
Re:What algorithm did Windows XP use to choose your initial ... by frou_dh on Thursday September 10, 2026 @08:54AM (#49642957)
I'm disappointed that it is not influenced by the username ... "You sound like a skateboard kinda person"
Re:What algorithm did Windows XP use to choose your initial ... by bayindirh on Thursday September 10, 2026 @09:01AM (#49643046)
Honestly,

I don't understand Microsoft. These guys solve the most mundane problems with most elegant solutions and with sound edge-case handling scenarios, then they destroy all the effort with subpar programming where it matters and with user hostile behavior where they can't botch it.

Re:What algorithm did Windows XP use to choose your initial ... by wongarsu on Thursday September 10, 2026 @10:22AM (#49644197)
That's simple. The Windows Kernel is a collection of mostly elegant solutions, with a strong peppering of backwards-compatibility cruft, all the way from NT3 to Windows 11. The Windows userland received a lot of effort until about Windows XP, and since then is a collection of subpar programming, half-finished projects and user-hostile patterns (with some notable exceptions)

Different teams with different goals and different management

Re:What algorithm did Windows XP use to choose your initial ... by Sohcahtoa82 on Thursday September 10, 2026 @12:26PM (#49646388)
> Different teams with different goals and different management

Not to mention the stack ranking policies that caused engineers to sabotage other people's work and avoid collaboration in order to keep themselves high on the stack in order to avoid being fired.

Re:What algorithm did Windows XP use to choose your initial ... by airstrike on Thursday September 10, 2026 @09:04AM (#49643083)
They're a very large organization with engineers of widely varying skills in projects with very different timelines.

I get what you mean, but it's really hard for any organization this size to drive consistent quality across the board.

Re:What algorithm did Windows XP use to choose your initial ... by waz0wski on Thursday September 10, 2026 @09:08AM (#49643124)
> // Assume everything in the dir is a vaild image file

Yep..

And image files were, and continue to be, a huge exploit attack vector

Re:What algorithm did Windows XP use to choose your initial ... by bayindirh on Thursday September 10, 2026 @10:04AM (#49643909)
We had bigger problems back then, and the function ran considerably rarely when compared the other parts of the OS, so it was a valid assumption at that age.

However, I still remember Wine laughing at Windows for WMF exploit and end up being affected from the same exploit. Now, that was a good laugh.

Re:What algorithm did Windows XP use to choose your initial ... by amelius on Thursday September 10, 2026 @09:20AM (#49643285)
They simply find some problems more interesting to solve than others.

Just like the rest of us.

Re:What algorithm did Windows XP use to choose your initial ... by amelius on Thursday September 10, 2026 @11:47AM (#49645751)
(Perhaps it shows that Apple engineers are pushed to grind at the boring problems more; therefore maybe it is better to work at Microsoft)
Re:What algorithm did Windows XP use to choose your initial ... by bayindirh on Thursday September 10, 2026 @12:52PM (#49646787)
Early in my career, I have read a blog post from someone senior about boring/entertaining work. In short it stated to following:

    Even if you work on exciting things, the project will always have boring parts.
    You'll need to develop these parts as well, so be prepared and show the same respect to all parts.
So, I'd personally rather work on all parts equally well rather than winging boring parts and create something subpar.
Re:What algorithm did Windows XP use to choose your initial ... by amelius on Thursday September 10, 2026 @01:16PM (#49647181)
Maybe. By the way, I chose Apple as an example but their software is just about as bad, only slightly better.
Re:What algorithm did Windows XP use to choose your initial ... by scrumper on Thursday September 10, 2026 @09:33AM (#49643468)
This is a fun example of the cognitive switch you have to employ when first starting to program a computer. It's extremely easy for a human to pick at random one thing from a pile of things: you reach out your hand and grab it, maybe swirling them around on the table first to shuffle the order. For a computer, there's no direct analogy to that. They just can't do it. And the human process is nothing even slightly like the one the computer follows: we don't have to count the sets and iterate over them, or count the items and then generate a random number to pick the nth item, or risk picking a null item.
Re:What algorithm did Windows XP use to choose your initial ... by rhplus on Thursday September 10, 2026 @10:38AM (#49644492)
I think this article highlights more the importance of understanding system limits in the 1990s versus today. No-one would care to much today if the code review for this feature had “files.count()” or whatever in it, but in the mid 90s that would have been a huge performance red flag because a user would literally hear their hard drive clicking away and see the blinkenlights.
Re:What algorithm did Windows XP use to choose your initial ... by layer8 on Thursday September 10, 2026 @10:48AM (#49644689)
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 ith 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.
Re:What algorithm did Windows XP use to choose your initial ... by madibo3156 on Thursday September 10, 2026 @11:40AM (#49645633)
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?
Re:What algorithm did Windows XP use to choose your initial ... by layer8 on Thursday September 10, 2026 @12:05PM (#49646057)
It will depend on details like file system fragmentation (Windows XP could run on FAT32), but it could conceivably make a perceptible difference on a slow HDD when there are many pictures in the directory. You also have to check more error cases, for when the second iteration fails for some reason. The mindset was probably "why complicate the code with multiple iterations and make it less efficient?" when the efficient solution is straightforward and arguably simpler.
Re:What algorithm did Windows XP use to choose your initial ... by linepogl on Thursday September 10, 2026 @01:00PM (#49646915)
Apart from the performance issues, it also prevents a bug. If some files get deleted between the first and the second pass, then you end up with unexpected behaviour and probably a crash.
Re:What algorithm did Windows XP use to choose your initial ... by sltkr on Thursday September 10, 2026 @04:02PM (#49649466)
The current implementation has the same race condition: the sampled file may be deleted by the time SHSetUserPicturePath() is called.
Re:What algorithm did Windows XP use to choose your initial ... by layer8 on Thursday September 10, 2026 @07:11PM (#49651379)
Yes, but the the implementation with the additional iteration also has to have extra checks for that iteration, because it can't blindly iterate to the ith file, as there may not be i files anymore. So the implementation gets more complex overall.
Re:What algorithm did Windows XP use to choose your initial ... by pixl97 on Thursday September 10, 2026 @04:56PM (#49650057)
Hard drives are measured in hundreds of IOPS at most. Then you have the 40 billion other things trying to eat those IOPS at startup.
Re:What algorithm did Windows XP use to choose your initial ... by ajsnigrutin on Thursday September 10, 2026 @12:36PM (#49646534)
That's why now we need gigabytes of ram to do the same thing we managed in 128Mb back then. I mean sure, there's an AI chatbot in your PDF viewer and ads in your start menu, but the functionality of many daily things is still the same.
Re:What algorithm did Windows XP use to choose your initial ... by ulrikrasmussen on Thursday September 10, 2026 @09:49AM (#49643693)
But the naive way of doing this also wouldn't really require two passes, right? It would just require more memory because you would first save all file names in an array (stopping at 100), then pick a random one in constant time.
Re:What algorithm did Windows XP use to choose your initial ... by wongarsu on Thursday September 10, 2026 @10:14AM (#49644070)
How do you know how big your array has to be in a single pass? I don't think the WinXP source uses vectors or similarly ergonomic auto-growing arrays. You could preallocate an array big enough for 100 paths of length MAX_PATH, but that's a bit wasteful. And it doesn't sound like you'd actually end up with fewer lines of code (in that flavor of C++, in python it would be different)
Re:What algorithm did Windows XP use to choose your initial ... by ulrikrasmussen on Thursday September 10, 2026 @11:04AM (#49645013)
Yes, you could allocate it on the stack. I think back then (still?) a filename could be at most 260 characters, each encoded with 16 bits, so about 52k of stack allocation.
Re:What algorithm did Windows XP use to choose your initial ... by wongarsu on Thursday September 10, 2026 @11:35AM (#49645537)
52k on the stack is pretty significant, given Windows defaults to just 1MB stack size per thread
Re:What algorithm did Windows XP use to choose your initial ... by adrianmonk on Thursday September 10, 2026 @02:53PM (#49648610)
You could use a linked list.

Practically speaking, I might just allocate an array of 100 pointers. That's only 400 bytes. Then as you encounter each filename, allocate just enough memory for the actual length of the string (plus null terminator) and store the pointer in the array.

Re:What algorithm did Windows XP use to choose your initial ... by ulrikrasmussen on Thursday September 10, 2026 @11:04PM (#49653086)
That will require a second pass though, because you have to free all your strings again.
Re:What algorithm did Windows XP use to choose your initial ... by wat10000 on Thursday September 10, 2026 @04:40PM (#49649873)
Depends on whether your naive approach prioritizes time or space.
[dead]
Re:What algorithm did Windows XP use to choose your initial ... by aimor on Friday September 11, 2026 @09:36AM (#49658212)
You could even calculate the 100 random numbers up front and potentially stop iterating early.
Re:What algorithm did Windows XP use to choose your initial ... by rietta on Thursday September 10, 2026 @10:13AM (#49644052)
I love the understated "some time ago" linking to a 2004 blog post. Raymond has been at this a long time :-)
Re:What algorithm did Windows XP use to choose your initial ... by SoftTalker on Thursday September 10, 2026 @12:17PM (#49646229)
I love that 2004 sounds like "some time ago" to some people. Seems like yesterday to me.
Re:What algorithm did Windows XP use to choose your initial ... by rietta on Thursday September 10, 2026 @12:55PM (#49646827)
Isn't that the truth! I remember it very, very well. Vividly even.
Re:What algorithm did Windows XP use to choose your initial ... by ang_cire on Thursday September 10, 2026 @12:58PM (#49646870)
My eyes glazed over when I saw "recursively", and I had to re-read the last couple paragraphs again to grok it, and it's very cool.
Re:What algorithm did Windows XP use to choose your initial ... by iJohnDoe on Thursday September 10, 2026 @01:15PM (#49647158)
Interesting topic.

I configured an account for someone with an Asian last name and it chose the fortune cookie.

Probably not voodoo, but it never seemed 100% random. More like some correlation was being done.

Re:What algorithm did Windows XP use to choose your initial ... by nerdo on Thursday September 10, 2026 @01:24PM (#49647304)
There'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))));

        for (var i = 0; i < skip; ++i) {
            if (!iterator.moveNext()) {
                return winner;
            }
            ++count;
        }

        if (!iterator.moveNext()) {
            return winner;
        }

        ++count;
        winner = iterator.current();
    }
}
Re:What algorithm did Windows XP use to choose your initial ... by canucker2016 on Thursday September 10, 2026 @02:53PM (#49648598)
Back in the day, Windows OS kernel programming avoided use of floating point numbers - certainly transcendental functions would've been frowned upon - when CPUs didn't include an FPU.

I don't know if they've relaxed this since the days of non-FPU CPUs - anyone know? If they let the Weather app use a webview, there must be some floating point usage in there.

This code is at a much higher level though - at the user shell level, explorer.exe.

Anyways, asking Google's AI to remove the above code's use of floating point results in code resembling the original version.

Re:What algorithm did Windows XP use to choose your initial ... by amag on Thursday September 10, 2026 @05:04PM (#49650157)
Better in which way? It doesn't seem like the RNG is much of a bottleneck[0]. So this code is just more complicated than the original[1] IMO. It is also most likely more costly by involving a bunch of extra divs, logs and (for XP-level HW) floating points, though admittedly the bottleneck on XP-level HW was most likely still the disk.

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 ... by adrianmonk on Thursday September 10, 2026 @02:45PM (#49648478)
> it’s more efficient because it reduces the amount of calls into the file system

OK, but isn't the kernel keeping the directory listing in the disk cache? Won't that prevent extra physical I/O if you do just read the directory twice?

If so, then in the second pass, it's all cache hits, and you're just paying the cost of calling into the file system. Hopefully that's pretty fast. But even if not, it's still absolutely dwarfed by the physical I/O required for the first pass. Windows XP era storage was spinning hard drives, not flash.

And if not, then I'm probably going to put my user icon coding task on the back burner and go ask the kernel team why a seemingly very common usage pattern isn't optimized.

(I realize he's not claiming the performance benefit was significant. I'm just trying to see it in the right perspective.)

Re:What algorithm did Windows XP use to choose your initial ... by bombela on Thursday September 10, 2026 @03:03PM (#49648735)
less work is always cheaper. no matter what.
Re:What algorithm did Windows XP use to choose your initial ... by sltkr on Thursday September 10, 2026 @04:06PM (#49649510)
It's not _strictly_ less work though: reservoir sampling requires generating many more random numbers. As usual, it's a tradeoff.
Re:What algorithm did Windows XP use to choose your initial ... by VVIQ2 on Thursday September 10, 2026 @04:39PM (#49649870)
That's clever. I wonder if this was done by an intern during his summer internship :)
Re:What algorithm did Windows XP use to choose your initial ... by majorchord on Thursday September 10, 2026 @05:50PM (#49650612)
Wouldn'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.

Re:What algorithm did Windows XP use to choose your initial ... by tyrust on Thursday September 10, 2026 @05:56PM (#49650664)
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 ... by majorchord on Thursday September 10, 2026 @06:28PM (#49650991)
But wouldn't changing the probability be even more random?
Re:What algorithm did Windows XP use to choose your initial ... by bspammer on Thursday September 10, 2026 @08:01PM (#49651767)
If you read the "Adapting Probabilities" section of the link above, there's a nice explanation of why changing the probability works.
Re:What algorithm did Windows XP use to choose your initial ... by Crestwave on Friday September 11, 2026 @02:03AM (#49654091)
The first iteration has a 100% chance of being marked as a winner. It only balances out to the same odds as a random selection because of the chances of it getting overwritten by the succeeding files.
Re:What algorithm did Windows XP use to choose your initial ... by cpeterso on Thursday September 10, 2026 @09:33PM (#49652476)
Raymond’s selectRandomFromIterator algorithm requires iterating over all the files. It seems like querying the file system for the number of files in a directory should be an O(1) operation. Then you just select random number N between [1, number of files] and iterate to the Nth file.

Why does Raymond assume counting the files is an O(n) operation?

Re:What algorithm did Windows XP use to choose your initial ... by orf on Thursday September 10, 2026 @11:02PM (#49653064)
Because counting the files is not an O(1) operation? It would be cool if it was, but that’s not reality?
Re:What algorithm did Windows XP use to choose your initial ... by cpeterso on Saturday September 12, 2026 @07:48PM (#49678455)
You’re right. I looked it up: getting the number of files in a directory in FAT and FAT32 file systems is O(n). I had assumed the count would be recorded in an inode-like structure but instead the file system must scan a directory table to count the non-null entries.
Re:What algorithm did Windows XP use to choose your initial ... by thenthenthen on Thursday September 10, 2026 @11:05PM (#49653090)
Some example images would have been nice!
Re:What algorithm did Windows XP use to choose your initial ... by anonymousiam on Friday September 11, 2026 @12:28AM (#49653560)
Re:What algorithm did Windows XP use to choose your initial ... by eru on Friday September 11, 2026 @12:30AM (#49653576)
The solution posted still requires O(n) calls to your random number generator.

You can do it in something like O(log n) calls while still sticking to a single forward only pass.

(But compared to reading the filesystem the rng calls were probably treated as free.)