示例#1
0
   std::string select_random( Query& q, const std::string& table, const std::string& column, const std::string& channel )
   {
      std::string sql = select( table, column, channel );
      int max = q.get_count( select_count( table, column, channel ) );

      boost::mt19937 rng( time( NULL ) ) ;
      boost::uniform_int<> uni(1, max);
      boost::variate_generator<boost::mt19937&, boost::uniform_int<> >
         die(rng, uni);

      sql += " AND id=" + boost::lexical_cast<std::string>( die() ) + ";";

      std::cout << sql << std::endl;
      q.free_result();

      std::string res = q.get_string( sql );
      q.free_result();
      return res;
   }