Density probability distribution in one-dimensional polytropic gas dynamics