DNA replication is an essential process in biology and its timing must be robust so that cells can divide properly. Random fluctuations in the formation of replication starting points, called origins, and the subsequent activation of proteins lead to variations in the replication time. We analyse these stochastic properties of DNA and derive the positions of origins corresponding to the minimum replication time. We show that under some conditions the minimization of replication time leads to the grouping of origins, and relate this to experimental data in a number of species showing origin grouping.