Пример #1
0
 Shrinkable<T> operator()(const Random &random, int size) const {
   auto r1 = random;
   auto r2 = r1.split();
   return shrinkable::mapcat(
       m_gen(r1, size),
       [=](const Gen<T> &innerGen) { return innerGen(r2, size); });
 }
Пример #2
0
 Shrinkable<U> operator()(const Random &random, int size) const {
   auto r1 = random;
   auto r2 = r1.split();
   const auto mapper = m_mapper;
   return shrinkable::mapcat(
       m_gen(r1, size), [=](T &&x) { return mapper(std::move(x))(r2, size); });
 }
Пример #3
0
  Shrinkable<Maybe<T>> operator()(const Random &random, int size) const {
    auto r = random;
    const auto x = r.split().next() % (size + 1);
    if (x == 0) {
      return shrinkable::lambda([]{ return Maybe<T>(); });
    }

    return prependNothing(shrinkable::map(
        m_gen(r, size), [](T &&y) -> Maybe<T> { return std::move(y); }));
  }
Пример #4
0
void Deck::shuffle(){
    Deck_t new_deck(0);
    while(m_deck.size() > 0){
        auto iter(m_deck.begin());
        advance(iter, m_gen() % m_deck.size());
        new_deck.push_front(*iter);
        m_deck.erase(iter);
    }
    m_deck = new_deck;
}
Пример #5
0
        void operator()()
        {
            auto ip = reinterpret_cast<iphdr *>(packet + 14);

            if (opt::async)
            {
                for(;;)
                {
                    for(unsigned int n = 0; n < m_pfq.size(); n++)
                    {
                        if (opt::rand_ip)
                        {
                            ip->saddr = m_gen();
                            ip->daddr = m_gen();
                        }

                        if (m_pfq[n].send_async(net::const_buffer(reinterpret_cast<const char *>(packet), opt::len), opt::batch))
                            m_sent->fetch_add(1, std::memory_order_relaxed);
                    }
                }
            }
            else
            {
                for(;;)
                {
                    for(unsigned int n = 0; n < m_pfq.size(); n++)
                    {
                        if (opt::rand_ip)
                        {
                            ip->saddr = m_gen();
                            ip->daddr = m_gen();
                        }

                        if (m_pfq[n].send_sync(net::const_buffer(reinterpret_cast<const char *>(packet), opt::len), opt::batch))
                            m_sent->fetch_add(1, std::memory_order_relaxed);
                    }
                }
            }
        }
Пример #6
0
  Shrinkable<T> operator()(const Random &random, int size) const {
    Random r(random);
    int currentSize = size;
    for (int tries = 0; tries < 100; tries++) {
      auto shrinkable =
          shrinkable::filter(m_gen(r.split(), currentSize), m_predicate);

      if (shrinkable) {
        return std::move(*shrinkable);
      }
      currentSize++;
    }

    throw GenerationFailure(
        "Gave up trying to generate value satisfying predicate.");
  }
int* RandomMaskGenerator::GetRandomMask()
{
    return p_data + (m_gen() % kNUMRANDOMMASKS) * m_maskSize;
}
Пример #8
0
 void operator()( sequence_type & seq ) {
     for( unsigned int i = 0; i < m_events; ++i ) {
         generator_result_type a = m_gen( seq, m_age );
         seq.addElement( a );
     }
 }
Пример #9
0
	std::locale getLocale( const std::string& name)
	{
		return m_gen( name);
	}
Пример #10
0
 Shrinkable<U> operator()(const Random &random, int size) const {
   return shrinkable::map(m_gen(random, size), m_mapper);
 }