Abstract
A possible quantum-mechanical origin of statistical mechanics is discussed, and microcanonical and canonical ensembles of bosons and fermions are derived from the stationary Schr\"odinger equation in a unified manner. The interaction Hamiltonians are constructed by the use of the discrete phase operators and the gauge-theoretical structure associated with them. It is shown how the interaction Hamiltonians stipulated by the gauge symmetry generate the specific patterns of entanglement that are desired for establishing microcanonical ensembles. A discussion is also made about the interrelation between random phases and perfect decoherence in the vanishing-interaction limit.