Move random number code from controller to model.