I think its potentially bad the common thinking I've seen where an interviewer ( and I've fallen into this trap ) thinks "whoa! X years of development and they can't do that! shakes head slowly". It's more a failure of the interviewer to find out what the X years of experience entailed. They could be insanely good at something really useful and just haven't coded many things like your random coding problem.
It can also just be nerves. It sucks, but it happens, and your brain just freezes up and kicks itself later in the evening for looking so stupid.
Besides general strategies of trying to lower the adversarial atmosphere I think the only full solution to this problem is to be open for them re-applying after some number of months. That at least codifies a second (or more) chance for candidates who really want to work for your company specifically.