Switched to log(rand) rather than exponentiated the energy to avoid overflow issues