  Long-lived magnetic fields are known to exist in upper main-sequence stars,
white dwarfs, and neutron stars. In order to explore possible equilibrium
configurations of the magnetic field inside these stars, we have performed
3D-magnetohydrodynamic simulations of the evolution of initially random
magnetic fields in stably stratified and barotropic stars with an ideal-gas
equation of state using the {\sc Pencil Code}, a high-order finite-difference
code for compressible hydrodynamic flows in the presence of magnetic fields. In
barotropic (isentropic) stars, we confirm previous results in the sense that
all initial magnetic fields we tried decay away, unable to reach a stable
equilibrium. In the case of stably stratified stars (with radially increasing
specific entropy), initially random magnetic fields appear to always evolve to
a stable equilibrium. However, the nature of this equilibrium depends on the
dissipation mechanisms considered. If magnetic diffusivity (or
hyperdiffusivity) is included, the final state is more axially symmetric and
dominated by large wavelengths than the initial state, whereas this is not the
case if only viscosity (or hyperviscosity) is present. In real stars, the main
mechanism allowing them to relax to an equilibrium is likely to be phase
mixing, which we argue is more closely mimicked by viscosity. Therefore, we
conclude that, depending on its formation mechanism, the equilibrium magnetic
field in these stars could in principle be very asymmetric.
