コード例 #1
0
ファイル: main.cpp プロジェクト: GOPRO1955/kodo
    /// Run the benchmark
    void run_benchmark()
    {
        assert(m_symbols_used == 0);
        assert(m_encoder);
        assert(m_decoder);

        std::vector<uint8_t> payload(m_encoder->payload_size());

        // Ensure the encoding vectors generated are randomized between
        // runs
        m_encoder->seed(rand());

        // The clock is running
        RUN{

            while(!m_decoder->is_complete())
            {
                m_encoder->encode(&payload[0]);

                if(m_distribution(m_random_generator))
                    continue;

                ++m_symbols_used;
                ++m_rank_used[m_decoder->rank()];
                m_decoder->decode(&payload[0]);
            }
        }
    }
コード例 #2
0
ファイル: random_constant.hpp プロジェクト: Akmal1983/fifi
 value_type value()
 {
     // We only create uint32_t sized random numbers
     assert(
         std::numeric_limits<uint32_t>::max() >= field_type::max_value);
     return (value_type)m_distribution(m_generator);
 }
コード例 #3
0
ファイル: algorithms_15.cpp プロジェクト: orcchg/CppCourse
 inline int next() {
   if (m_count > COUNT) {
     return STOP;
   }
   ++m_count;
   return m_distribution(m_rng);
 }
コード例 #4
0
/**
 * @return A generated rating
 */
double RatingNormalDist::rating() {
   double rating;
   do {
      rating = m_distribution(m_generator);
   } while(rating < 1 || rating > m_scaleSize);
   
   return rating;
} // rating
コード例 #5
0
    template<class T> inline void insert(T value)
    {
        m_summary(static_cast<double>(value));
        m_histogram(static_cast<double>(value));

        int sample = m_distribution(m_rng);
        if (static_cast<boost::uint32_t>(sample) < m_sample_size)
            m_sample.push_back(static_cast<double>(value));
        return;
    }
コード例 #6
0
ファイル: Stats.hpp プロジェクト: pramsey/PDAL
    template<class T> inline void insert(T value)
    {
        m_summary(static_cast<double>(value));
        if (m_doSample)
        {
            uint32_t sample = (uint32_t)m_distribution(m_rng);
            if (sample < m_sample_size)
                m_sample.push_back(static_cast<double>(value));
        }

        if (m_doExact == true)
            m_counts[(int32_t)value]++;
    }
コード例 #7
0
/* Default constructor
    m_maskSize is a multiple of REDUCTION_BLOCKSIZE_SIZE rounded up. This allows
    for performance improvements in some CUDA kernels.
*/
RandomMaskGenerator::RandomMaskGenerator()
    : p_data(nullptr),
    m_maskSize( kSUBSAMPLE_SIZE ),
    m_gen(std::clock()),
    m_distribution(0, kSCREEN_HEIGHT * kSCREEN_WIDTH - 1)
{
    
    // Allocate memory for all the sample masks and initialize all bits to 1
    p_data = new int[m_maskSize * kNUMRANDOMMASKS];
    for(unsigned long i = 0; i < m_maskSize * kNUMRANDOMMASKS; ++i)
    {
        p_data[i] = INT_MAX;
    }
    //std::fill_n(p_data, m_maskSize * kNUMRANDOMMASKS, ULONG_MAX);

    std::cout << "Mask Size: " << m_maskSize << std::endl;

    for(unsigned int i = 0; i < kNUMRANDOMMASKS; ++i)
    {
        std::cout << "Making Mask " << i << std::endl;

        for(int j = 0; j < m_maskSize; ++j)
        {
            int newIndex = m_distribution(m_gen);
            while( MaskAlreadyContainsIndex(p_data + (i * m_maskSize), m_maskSize, newIndex))
            {
                newIndex = m_distribution(m_gen);
            }
            p_data[i * m_maskSize + j] = newIndex;
        }
    }

    for(unsigned int i = 0; i < kNUMRANDOMMASKS; ++i)
    {
        std::cout << "Sorting Mask " << i << std::endl;

        qsort(reinterpret_cast<void*>(p_data + (i * m_maskSize)), m_maskSize, sizeof(int), &intComp);
    }
}
コード例 #8
0
bool MetropolisTest::test(Array<double> &trial_coords, double trial_energy,
        Array<double>& old_coords, double old_energy, double temperature,
        MC * mc)
{
    double rand;
    double w;
    double wcomp;
    bool success = true;
    wcomp = (trial_energy - old_energy) / temperature;
    w = exp(-wcomp);
    if (w < 1.0) {
        rand = m_distribution(m_generator);
        if (rand > w) {
            success = false;
        }
    }
    return success;
}
コード例 #9
0
ファイル: CustomWidget.cpp プロジェクト: TankOs/SFGUI
		// InvalidateImpl is called by SFGUI whenever something happens
		// that might make the widget look different. It returns an
		// sfg::RenderQueue containing the graphical elements that will
		// be rendered to display the widget on the screen.
		std::unique_ptr<sfg::RenderQueue> InvalidateImpl() const override {
			// In order to support engine themes, you should not hard-code
			// graphical parameters, but instead retrieve the properties you need
			// from the currently active engine. These properties determine
			// what your widget looks like and can be adjusted to affect a
			// large number of widgets at the same time.
			auto background_color = sfg::Context::Get().GetEngine().GetProperty<sf::Color>( "BackgroundColor", shared_from_this() );
			const auto& font_name = sfg::Context::Get().GetEngine().GetProperty<std::string>( "FontName", shared_from_this() );
			auto font_size = sfg::Context::Get().GetEngine().GetProperty<unsigned int>( "FontSize", shared_from_this() );

			// Fonts are stored in the engine resource manager. Once you have the name
			// of a font that has been loaded, you can get it from the resource manager.
			const auto& font = sfg::Context::Get().GetEngine().GetResourceManager().GetFont( font_name );

			std::unique_ptr<sfg::RenderQueue> queue( new sfg::RenderQueue );

			if( GetLabel().getSize() > 0 ) {
				auto metrics = sfg::Context::Get().GetEngine().GetTextStringMetrics( GetLabel(), *font, font_size );
				metrics.y = sfg::Context::Get().GetEngine().GetFontLineHeight( *font, font_size );

				// SFGUI widgets are made out of elementary pieces.
				// You have to request the renderer to give you each of
				// these pieces through one of the Create* methods.
				// You add these pieces to the RenderQueue that you return and it
				// will be rendered where the widget is displayed on the screen

				// Refer to the sfg::Renderer documentation for more information
				// on the Create* methods.

				auto inverted_color = sf::Color::White - background_color;
				inverted_color.a = 255;

				// Outer pane.
				queue->Add(
					sfg::Renderer::Get().CreatePane(
						sf::Vector2f( 0.f, 0.f ),
						sf::Vector2f( GetAllocation().width, GetAllocation().height ),
						5.f,
						inverted_color,
						background_color,
						20.f
					)
				);

				auto inner_border_color = sf::Color::Green;

				// If the widget is active (currently pressed) change the inner border to red
				if( GetState() == State::ACTIVE ) {
					inner_border_color = sf::Color::Red;
				}

				// Inner pane.
				queue->Add(
					sfg::Renderer::Get().CreatePane(
						sf::Vector2f( GetAllocation().width / 4.f, GetAllocation().height / 4.f ),
						sf::Vector2f( GetAllocation().width / 2.f, GetAllocation().height / 2.f ),
						5.f,
						sf::Color(
							static_cast<sf::Uint8>( m_color_distribution( m_generator ) ),
							static_cast<sf::Uint8>( m_color_distribution( m_generator ) ),
							static_cast<sf::Uint8>( m_color_distribution( m_generator ) ),
							255
						),
						inner_border_color,
						20.f
					)
				);

				sf::Text text( GetLabel(), *font, font_size );

				// Set the text color to white.
				text.setFillColor( sf::Color::White );

				// Randomize the applied offset a bit
				auto x_offset = ( GetState() == State::ACTIVE ) ? static_cast<float>( m_distribution( m_generator ) ) : 0.f;
				auto y_offset = ( GetState() == State::ACTIVE ) ? static_cast<float>( m_distribution( m_generator ) ) : 0.f;

				text.setPosition(
					GetAllocation().width / 2.f - metrics.x / 2.f + x_offset,
					GetAllocation().height / 2.f - metrics.y / 2.f + y_offset
				);

				// Text.
				queue->Add( sfg::Renderer::Get().CreateText( text ) );
			}

			return queue;
		}
コード例 #10
0
ファイル: RNG.hpp プロジェクト: storm20200/WaterEngine
 /// <summary> Retrieves the next random number from the sequence. </summary>
 T getRandom()                           { return m_distribution (m_generator); }
コード例 #11
0
ファイル: RNG.hpp プロジェクト: storm20200/WaterEngine
 /// <summary> Retrieves the next random number from the sequence. </summary>
 T operator()()                          { return m_distribution (m_generator); }
コード例 #12
0
ファイル: random.hpp プロジェクト: Irelevance/Opengl
 SampleType          next() 
 {
     return m_distribution( m_engine );
 }