fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. class Generator
  8. {
  9. public:
  10. Generator(int min, int max, int cnt) {
  11. int value;
  12. while(v_.size() != cnt) {
  13. value = rand() % (max - min + 1);
  14. if (std::find(v_.begin(), v_.end(), value) == v_.end()) {
  15. v_.push_back(value);
  16. }
  17. }
  18. }
  19. void print_result(void) {
  20. for (std::vector<int>::const_iterator i = v_.begin(); i != v_.end(); ++i)
  21. std::cout << *i << ' ';
  22. std::cout << std::endl;
  23. }
  24.  
  25. private:
  26. vector<int> v_;
  27. };
  28.  
  29.  
  30. int main() {
  31. Generator g(1, 50, 5);
  32. g.print_result();
  33. return 0;
  34. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
33 36 27 15 43