fork(2) download
  1. #include <cstdint>
  2. #include <vector>
  3. #include <limits>
  4. #include <ctime>
  5. #include <cstdint>
  6. #include <random>
  7. #include <cstdlib>
  8. #include <algorithm>
  9.  
  10. int main()
  11. {
  12. const int NUMS = 100;
  13. int cds[NUMS];
  14.  
  15. std::srand(static_cast<unsigned long>(std::time(nullptr)));
  16. auto rand = std::bind([]() { return std::rand(); });
  17. auto seed = [&rand](int n) {
  18. std::vector<std::uint32_t> v(n);
  19. std::generate(v.begin(), v.end(), rand);
  20. return std::seed_seq(v.begin(), v.end());
  21. }(10);
  22.  
  23. std::mt19937 engine(seed);
  24. std::uniform_int_distribution<> dis(0, NUMS - 1);
  25.  
  26. std::shuffle(cds, cds + NUMS, dis(engine));
  27. }
  28.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from /usr/include/c++/4.8/random:52:0,
                 from prog.cpp:6:
/usr/include/c++/4.8/bits/random.tcc: In instantiation of ‘std::uniform_int_distribution<_IntType>::result_type std::uniform_int_distribution<_IntType>::operator()(_UniformRandomNumberGenerator&, const std::uniform_int_distribution<_IntType>::param_type&) [with _UniformRandomNumberGenerator = int; _IntType = unsigned int; std::uniform_int_distribution<_IntType>::result_type = unsigned int]’:
/usr/include/c++/4.8/bits/stl_algo.h:4410:67:   required from ‘void std::shuffle(_RAIter, _RAIter, _UGenerator&&) [with _RAIter = int*; _UGenerator = int]’
prog.cpp:26:44:   required from here
/usr/include/c++/4.8/bits/random.tcc:883:4: error: ‘int’ is not a class, struct, or union type
    _Gresult_type;
    ^
/usr/include/c++/4.8/bits/random.tcc:886:4: error: ‘int’ is not a class, struct, or union type
    __uctype;
    ^
/usr/include/c++/4.8/bits/random.tcc:903:32: error: expression cannot be used as a function
        __ret = __uctype(__urng()) - __urngmin;
                                ^
/usr/include/c++/4.8/bits/random.tcc:930:36: error: expression cannot be used as a function
   __ret = __tmp + (__uctype(__urng()) - __urngmin);
                                    ^
/usr/include/c++/4.8/bits/random.tcc:935:28: error: expression cannot be used as a function
    __ret = __uctype(__urng()) - __urngmin;
                            ^
stdout
Standard output is empty