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 utilized the RtlRandomEx random number generator to select an initial user picture from the %ALLUSERSPROFILE%\Application Data\Microsoft\User Account Pictures\Default Pictures directory. The generator began with the current value of GetTickCount() as the seed. The function employed a one-pass random selection algorithm, which was more efficient compared to the naïve two-pass algorithm that required counting all items and then randomly picking a number from 1 to n, followed by a second iteration to find the item at that index.

This one-pass algorithm avoided the need for multiple file system calls and prevented complications if the number of files in the directory changed during runtime. It functioned by first selecting an item randomly from the first n - 1 items and then switching to the nth item with a 1/n probability, following a recursive approach.

The algorithm concluded after sampling 100 pictures to prevent potential issues if the directory contained a large number of files.

Written by urgent.news from Lobsters'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 →