For example, you can use std :: random_shuffle, since you have a finite number of integer coordinates. So just shuffle this set of vectors / positions around. You can also pass your own RNG to random_shuffle as a function object.
Example:
#include <algorithm> //for copy and random_shuffle #include <utility> //for pair and make_pair #include <vector> ... std::vector<std::pair<int, int> > coords; std::vector<std::pair<int, int> > coords20(20); for(int y=-8; y<=8; y+=2) for(int x=-8; x<=8; x+=2) coords.push_back(std::make_pair(x,y)); std::random_shuffle(coords.begin(), coords.end()); std::copy(coords.begin(), coords.begin() + 20, coords20.begin());
Mads elvheim
source share