Let's say I have a RAID 1 array with two mirrored drives. One goes bad. If I order a spare online and just put it in, the hardware controller will rebuild the array, right? How does it know which drive to mirror? What if the drive I ordered wasn't wiped and was in another RAID1 array? Is there any risk of it mirroring that drive's contents to my drive?
For most hardware RAID cards, when you remove the failed drive it will know that it is gone. Then when you install a new drive of the same size it will just add that drive as the replacement for the removed drive that failed.
In the case of a drive that was in another RAID, the controller knows the ID of the RAID set that is written to the drives. If it finds an ID on the new drive that doesn't match the array it is configured for, it will not join it to the array. The management interface for the RAID card either by entering it during boot time or via the RAID management software within the OS will have an option to import a foreign disk or in some other way force a disk with a foreign configuration to be use.
Firstly, this depends on what RAID you are using.
Different raid controllers will do things differently.
I.e a HP raid card will sit and cry if it sees raid meta data already on the new drive. You will be able to see which drive failed and in which bay by running (Linux)
hpacucli ctrl all show config
Others might not be so strict. You can also (if possible) look at the server physically, spot which has the red failed led on.
Software raid is different. mdadm on Linux will put the drive in and overwrite the contents of you add it to the array, but not automatically. In that instance, run sfdisk -d /dev/sda for example in that case to see if the replacement drive has a file system partition on it.
I appreciate it was a broad answer but if you could update your question with more specifics we can help you more :)
To prevent this being an issue, you could wipe the drive before adding it to the array. Depending on the system the RAID is in, you could either use an external caddy (SATA), load into Windows and use Disk Part to clean the drive. If it's SAS, I'd remove the existing good drive, connect the new drive, boot into a Windows installation DVD/USB and run disk part from there. Turn off, connect drives as normal, load into the RAID controller and add the new drive to the array, which should inform you it will wipe the selected drive as it adds it to the RAID.
As has been said earlier, you shouldn't have a problem as the RAID controller should have mitigation to prevent this from happening but if you are unsure, remove the RAID from the equation and wipe the drive prior.