Use actual sample number to calculate averge value

Sometimes, we don't have enough samplings to fill in predefined
sample array. It is inaccurate to use pre defined sample number
to calculate average values.