# Histogram range of bins

Mathematica misrepresents data with Histogram by choosing "arbitrary" range in its bins.

For example the command:

Histogram[Table[RandomReal[], {100000}]]


Gives the expected picture:

However, the command:

Histogram[Table[1.005 RandomReal[], {100000}]]


Gives the following:

As you can see the last bar is much shorter than the rest. This clearly happens because Mathematica rounds up severely the range of the values and the last bins falls mostly out of the range. Can Mathematica be convinced not to do that?

From details sections on bin specs, if you need n bins you can do

$$\{x_{min},x_{max}, (x_{max}-x_{min})/n \}$$

for instance in your case of 21 bins:

Histogram[RandomReal[1.005, 100000], {0, 1.005, 1.005/21}]


To make sure for sanity the right edge of the last bin is really where it should be you can zoom in on it:

Histogram[RandomReal[1.005,100000],{0,1.005,1.005/21},
PlotRange->{{.95,1.05},Automatic}]