Monday, July 22, 2013

From "list" in python to "vector" in C++

We can do this easily in Python but we need some new things to do this in C++.
An example of randomly generating heterogeneous numbers is shown below.


      std::vector<int> groupI;
      int k;
      do {
      k = 0 + (std::rand() % (int)(41 - 0 + 1));     
      }
      while (std::find(groupI.begin(), groupI.end(), k) != groupI.end());
      groupI.push_back (k);   


And we got it. :)

No comments:

Post a Comment