This will avoid painful debugging and unnecessary crashes in favor of a clear warning message if, for any unanticipated reason, numberOfConfigured ranges doesn't match scan.getRanges().length - as it happened to us when trying to use this code.

The reason numberOfConfiguredRanges could be different than scan.getRanges().length is because the former is calculated at configuration time (FF command) but the number of ranges on each scan can technically be different for each distance acquisition request (MD).