fork download
  1. #include <boost/coroutine/coroutine.hpp>
  2. #include <boost/coroutine/all.hpp>
  3. #include <iostream>
  4. #include <random>
  5.  
  6.  
  7. typedef boost::coroutines::coroutine<int()> coroutine_type;
  8.  
  9.  
  10. void
  11. random_generator(coroutine_type::caller_type& coroutine){
  12. std::mt19937 engin;
  13. std::uniform_int_distribution<int> distribution(1, 6);
  14. coroutine(engin());
  15.  
  16. while( 1 ){
  17. coroutine(distribution(engin));
  18. }
  19. }
  20.  
  21.  
  22. int
  23. main(){
  24. coroutine_type random(random_generato);
  25.  
  26. for(int i = 0 ; i < 20 ; ++i){
  27. std::cout << random() << std::endl;
  28. }d::endl;
  29.  
  30. return 0;
  31. }
  32.  
  33.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty