We introduce a new way to perform swaps between replicas in replica exchange molecular dynamics simulations. The method is based on a generalized canonical probability distribution function and flattens the potential of mean force along the temperature coordinate, such that a random walk in temperature space is achieved. Application to a Go model of protein A showed that the method is more efficient than conventional replica exchange. The method results in a constant probability distribution of the replicas over the thermostats, yields a minimum round-trip time between extremum temperatures, and leads to faster ergodic convergence.