Skip to content
Tech News
← Back to articles

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

read original get Knuth: The Art of Computer Programming, Vol. 2 → more articles
Why This Matters

A Microsoft veteran's explanation of how Windows XP picked your default account picture is a small but instructive look at how shipping OS code makes pragmatic engineering tradeoffs. The answer — RtlRandomEx seeded with GetTickCount, plus a single-pass reservoir sampling selection — shows why developers optimize around the real bottleneck (file system enumeration) rather than the math.

Key Takeaways
Worth a Look

Knuth: The Art of Computer Programming, Vol. 2 — If reservoir sampling and seeded random number generators pique your curiosity, Knuth's Volume 2 (Seminumerical Algorithms) is the classic deep dive into random number generation and sampling techniques. It's the reference that explains why one-pass tricks like the k=1 reservoir selection Windows XP used are so elegant. A handsome hardcover that earns its spot on any programmer's shelf.

See Knuth: The Art of Computer Programming, Vol. 2 on Amazon → Affiliate link — we may earn a commission on purchases, at no extra cost to you. Product picked by AI based on this article; it is not a tested recommendation.

I noted some time ago that Windows XP chose your initial picture at random from among the pictures in the %ALLUSERSPROFILE%\ Application Data\ Microsoft\ User Account Pictures\ Default Pictures directory. But it seems people want to know more.

Has anyone attempted to figure out the RNG for how Windows XP determines what profile picture is used on first account creation? — Xeno (@XenoPanther) December 11, 2025

The random number generator is our friend RtlRandomEx , using the current value of GetTickCount() as the initial seed.

The function uses a one-pass random selection algorithm. I can immediately think of two benefits of this decision. First, compared to the naïve two-pass algorithm of counting up all the items, then randomly picking a number from 1 to n , and then iterating a second time to find the item at that index, it’s more efficient because it reduces the amount of calls into the file system, which is where the bottleneck is. Furthermore, the one-pass algorithm avoids complications if the number of files in the directory changes while the code is running.

The one-pass algorithm is a special case of reservoir sampling, where k is 1. This special case permits a tailored algorithm that is much simpler.

selectRandomFromIterator(iterator) { var count = 0; var winner = null; while (iterator.moveNext()) { ++count; if (uniform_random(min: 1, max: count) == count) { winner = iterator.current(); } } return winner; }

The way this algorithm works is by observing that in a collection of n items, the last item has a 1/ n chance of being randomly selected. If it isn’t selected, then you need to select randomly from the first n − 1 items, which you can solve recursively.

Playing the recursion forward, you start with the base case which is that if you have a list of 1 item, then your only choice is to chose that item. Otherwise, if you have a list of n items, first choose an item randomly from the first n − 1, and then switch to the n th item with a 1/ n probability.