I was wondering what's the best way to distribute something over a set number of objects. I'm trying to create a minesweeper game where there are a certain number of tiles, and a set number of mines, but I'm not sure the best way to randomly distribute numbers over a range.
Concretely, if I had a vector of say 400 objects, what's the best way to randomly distribute one boolean attribute so that like 30 of those 400 had true and the rest were false?
struct Tile {
bool mine;
// ...
};
std::vector<Tile> v(400);
I was thinking perhaps something like a probability system where a set number of my tiles absolutely had to have the attribute, and I could create a numbering vector of all the objects and roll random numbers, then removing those objects from the vector until the met number of mines were set.