Urgent.News

What's breaking now, across thousands of outlets.

Tech

What algorithm did Windows XP use to choose your initial user picture?

Article URL: https://devblogs.microsoft.com/oldnewthing/20260909-00/?p=112683 Comments URL: https://news.ycombinator.com/item?id=49640646 Points: 288 # Comments: 140

Windows XP used the RtlRandomEx function to randomly select an initial user picture from the %ALLUSERSPROFILE%\Application Data\Microsoft\User Account Pictures\Default Pictures directory. This random number generator relied on the current value of GetTickCount() as its seed. Instead of employing a two-pass algorithm, which would involve counting all the items and then picking a random number from 1 to n and iterating again to find the item at that index, Windows XP opted for a more efficient one-pass algorithm.

This special case of reservoir sampling simplified the process and minimized the number of file system calls, acting as a bottleneck. The one-pass algorithm worked by choosing the last item with a 1/n probability, and if it wasn't selected, recursively selecting from the first n-1 items. The code also included a safety check, stopping after sampling 100 pictures to prevent potential issues if a directory contained a million files.

Raymond, a long-time contributor to Windows, played a key role in the evolution of the operating system and shared insights on his website, The Old New Thing.

Written by urgent.news from Hacker News Best's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

This story

This is one outlet's version. Read the fullest account.

Read the original at devblogs.microsoft.com →

More in Tech

More from Thursday 10 September →