dimanche 1 novembre 2015

Generate random numbers exaclty once

I need to create a set of random numbers between 0 and 800. The problem is at the moment that I need to do this fast and each number shall be returned only once.

My current approach is:

  • Create a std::vector containing the numbers from 0 to 800
  • Pick a number using numberVector[rand() % numberVector.length()]
  • Delete this number from the vector

I have to do this very often and my current approach is slow. Is there some way to speed things up here?




Aucun commentaire:

Enregistrer un commentaire