How to minimize the impact of erroneous sensor readings? A group including myself are using the Lego Mindstorm kit to design a robot that is going to compete in a school competition.  However, the sensors aren't as reliable as we would like them to be, particularly the ultrasonic sensor, which is what we're using to judge how far away objects are from our robot.  The problem that we face is that every so often the sensor returns a value that is just wrong: in a set of 3 datapoints for an object that is 45 units away, we'd possibly get values like 45, 45, and then 186.  The erroneous values are not consistent, nor is the amount by which the error occurs.  We also can't judge the probability of an erroneous value occurring.  Our current algorithm takes the average of a small number (i.e. 3) of datapoints, but we've realized that if the number of datapoints is small, then the average could be distorted greatly by erroneous values.  If the number of datapoints is large, then it takes a long time for the robot to get all of the sensor readings.  

What do you recommend as a process to reduce the impact of erroneous sensor readings?

I'm sorry if I'm posting this question in the wrong location, but this problem seemed more closely linked to mathematics than to programming.
I have quite some experience in Lego Mindstorms and I can tell you that their ultrasonic sensor is extremely inaccurate as you described - from what I read online, the ultrasonic rays travel in a V shaped path instead of in a straight line (it causes readings not to be linear with distance). Detecting an object with a round surface makes it worse, because the ultrasonic rays end up scattering all over the place.

What we (my team and I did) tried to do was to cover up half of each of the sensor's emitting and receiving outlet hole so as to force the ultrasonic rays to travel in straight lines. We also tried taking averages, root mean squares, differentials, integrals and what not of samples instead - but both did little to solve the problem, especially when sensing across distances that are far away (> 100 cm). 

We ended up switching to one of Mindsensors' laser based distance sensors.