I guess the easy way would be to calculate the minimum and maximum of the data you have, then calculate L = max - min
. Then you divide L
by the desired bin width (I'm assuming this is what you mean by bin size) and use the ceiling of this value as the number of bins.