On the foundations of statistical mechanics