stdvector - How is it possible to randomly remove an element from vector< vector<short> >? -


below sudoku initializer, attempting create function based on user input, erases random element the board. random element can removed part of board.

class cell{     bool m_occu; //occupied shown '.'     int m_num;  public:     cell() : m_occu(false), m_num(0) {}     void setmark(const int num){m_num = num; m_occu = true;}     bool ismarked() const { return m_occu; }     int getnum(){ return m_num;}     friend ostream& operator << (ostream& o, const cell& c){         if (!c.m_occu) return o << setw(2) << '-';         return o << setw(2) << c.m_num;     } };  class board {     vector<vector <cell> >m_map;     bool col_row;  public:     board() {         vector<cell> a_row(9);         col_row = false; (int = 0; < 9; ++i)         {             for(int j = 0; j < 9; j++)             {                 a_row[j].setmark(j+1);             }             random_shuffle(a_row.begin(), a_row.end());             m_map.push_back(a_row);         }     }      void erase(){      } 

here code erase function:

void erase(std::vector your_vector){    your_vector.erase(your_vector.begin() + random(1,your_vector.size())); } 

and code random number generation:

int random(int min, int max) //range(min, max) {    bool first = true;    if ( first )     {         srand(time(null)); //seeding first time       first = false;    }    return min + rand() % (max - min); }  

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -