Guest User

Untitled

a guest
Jul 16th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <ctime>
  3.  
  4. #include <iostream>
  5. #include <vector>
  6.  
  7. unsigned int random(const unsigned int mod)
  8. {
  9. return std::rand() % mod;
  10. }
  11.  
  12. std::vector<unsigned int> Data;
  13. unsigned int Count;
  14.  
  15. unsigned int Get()
  16. {
  17. const unsigned int idx = random(Count);
  18. const unsigned int value = Data[idx];
  19. Data[idx] = Data[--Count];
  20. return value;
  21. }
  22.  
  23. int main(const int argc, const char* const* const argv)
  24. {
  25. using namespace std;
  26.  
  27. srand((unsigned) time(NULL));
  28.  
  29. const static unsigned int Length = 16;
  30. Data = vector<unsigned int>(Length);
  31. Count = Length;
  32. for(unsigned int i=0; i<Length; ++i)
  33. {
  34. Data[i] = i;
  35. }
  36.  
  37. for(unsigned int i=0; i<Length; ++i)
  38. {
  39. cout << Get() << endl;
  40. }
  41. return 0;
  42. }
Add Comment
Please, Sign In to add comment