Unless I'm hugely mistaken, the rock chosen is the rock closest to the dwarf executing the task at the time the dwarf receives the order.
If the dwarf happens to be standing in the workshop (after having finished the previous job), then the rock he picks will (coincidently) be the closest one to the workshop. Hence the reason that a stockpile next to the workshop is useful.
That said, the first rock is less predictable. If your dwarf is standing in the middle of your Bauxite pile when he gets the bright idea to make a door, he'll grab the Bauxite (which is closest to him), and then haul it to the workshop. Hence the reason that Danaru lost his bauxite to an over-zealous mason - the wagon is the default 'idle' zone, so your mason was probably hanging around the wagon when he started the "Construct rock door" task, and the bauxite was right next to him. This nature is what makes the first stone seem 'random', too.
The other nasty fact about rock selection is that the distance is the absolute distance, not the path distance. Z-levels count as a single tile. That means that, with a mason's workshop smack dab in the centre of a 9x9 dining hall, the mason would rather grab a stone from 6 levels above/below his current position than grab a stone from the edge of the room, even if getting down 6 levels requires him to spend the next five-ish minutes walking. It's kind of counter-intuitive, since both stairs and z-level transistions make most fortress designers plan horizontally, not vertically. It's very frustrating to try and clear out a room when you're digging another one directly beneath it - {f}orbid any newly-mined stone, and after your dwarves stop grumbling, they'll use the stuff you want them to use.