This one comes from locked door generation algorithm I was thinking about for Carceri, but what the hell - it could be used anywhere.
How it works:
1) Random map generator creates new room.
2) If room has 1 exit, then continue, else stop_check_locked.
3) If room has no stairs (maybe except for bonus ones) then continue, else stop.
4) If this is the last room to be generated, then stop, else continue (otherwise you won't be able to place keycard; I don't know if it's possible to return to previously created ones in order to do so, since you'll have to somehow check, if they are locked or not, and keycards should either be never locked, or locked in sequence, that is possible to follow)
...maybe some other conditions?
4) x\100 chance door gets one of 3 colours. If rolled succesfully, block entrance with door, generate keycard (and maybe some additional monsters around it; maybe additional items too).
This way it's impossible to make game unplayable by locking vital rooms, and searching for keycards allows to get some additional supplies...
Keycard can be not simple laying around, but carried by some monster not inside locked room... BTW, locked rooms should have indestructible walls or the whole point would be missed.
Actually, stairways can be locked too, but condition of only one exit should be met anyway; otherwise you'll get lost in uberdifficult checks...