C++ (Cpp) rand Examples

C++ (Cpp) rand - 30 examples found. These are the top rated real world C++ (Cpp) examples of rand extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
void SDriver::run(void) {

    generateValues();

    int cur_val = 0;
    int num_found = 0;

    clock_t t1,t2;

    t1=clock();
    for( int iter = 0; iter < numValues; iter++ ) {
        if( binSearch(cur_val) ) num_found++;
        cur_val += (rand() % 4) + 4;
    }
    t2 = clock();

    float diff = ((float)t2 - (float)t1)/CLOCKS_PER_SEC;
    std::cout << "Bin search took " << diff
              << " seconds to execute " <<std::endl;

    cur_val = 0;
    t1 = clock();
    for( int iter = 0; iter < numValues; iter++ ) {
        if( bforceSearch(cur_val) ) num_found++;
        cur_val += (rand() % 4) + 4;
    }
    t2 = clock();

    diff = ((float)t2 - (float)t1)/CLOCKS_PER_SEC;
    std::cout << "Brute force search took " << diff
              << " seconds to execute " <<std::endl;


}
    void UpdateAI(const uint32 diff)
    {
        if (!UpdateVictim())
            return;

        //Check for War Stomp
        if (War_Stomp_Timer <= diff)
        {
            DoCast(m_creature->getVictim(), WAR_STOMP);
            War_Stomp_Timer = 25000 + rand()%15000;
        } else War_Stomp_Timer -= diff;

        //Check for Arcane Volley
        if (Arcane_Volley_Timer <= diff)
        {
            DoCast(m_creature->getVictim(), ARCANE_VOLLEY);
            Arcane_Volley_Timer = 20000 + rand()%15000;
        } else Arcane_Volley_Timer -= diff;

        //Check for Summon Treants
        if (Summon_Treants_Timer <= diff)
        {
            SummonTreants();
            Summon_Treants_Timer = 45000;
        } else Summon_Treants_Timer -= diff;

        DoMeleeAttackIfReady();
    }
Example #3
0
// blip is for a target immune to sensors, so cause to flicker in/out with mild distortion
void radar_blip_draw_flicker_std(blip* b)
{
    int xdiff = 0, ydiff = 0, flicker_index;

    if ((b - Blips) & 1)
    {
        flicker_index = 0;
    }
    else
    {
        flicker_index = 1;
    }

    if (timestamp_elapsed(Radar_flicker_timer[flicker_index]))
    {
        Radar_flicker_timer[flicker_index] = timestamp_rand(50, 1000);
        Radar_flicker_on[flicker_index] ^= 1;
    }

    if (!Radar_flicker_on[flicker_index])
    {
        return;
    }

    if (rand() & 1)
    {
        xdiff = -2 + rand() % 4;
        ydiff = -2 + rand() % 4;
    }

    radar_draw_circle_std(b->x + xdiff, b->y + ydiff, b->rad);
}
Example #4
0
        void Reset()
        {
            ArcaneMissiles_Timer = 2000;
            m_uiWrathOfTheAstromancer_Timer = 15000;
            BlindingLight_Timer = 41000;
            Fear_Timer = 20000;
            VoidBolt_Timer = 10000;
            Phase1_Timer = 50000;
            Phase2_Timer = 10000;
            Phase3_Timer = 15000;
            AppearDelay_Timer = 2000;
            BlindingLight = false;
            AppearDelay = false;
            Wrath_Timer = 20000+rand()%5000;//twice in phase one
            Phase = 1;
            Wrath_Timer = 20000+rand()%5000;//twice in phase one

            if (pInstance)
                pInstance->SetData(DATA_HIGHASTROMANCERSOLARIANEVENT, NOT_STARTED);

            me->SetArmor(defaultarmor);
            me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
            me->SetVisible(true);
            me->SetFloatValue(OBJECT_FIELD_SCALE_X, defaultsize);
            me->SetDisplayId(MODEL_HUMAN);

            Summons.DespawnAll();
        }
StarfieldBackgroundStars::StarfieldBackgroundStars (Type type) :
    sur(),
    x_pos(),
    y_pos(),
    x_add(),
    y_add()
{
    switch (type)
    {
    case SMALL_STAR:
        sur = Sprite("game/stars/small_star");
        break;
    case MIDDLE_STAR:
        sur = Sprite("game/stars/middle_star");
        break;
    case LARGE_STAR:
        sur = Sprite("game/stars/large_star");
        break;
    }

    x_pos = float(rand() % WorldObj::get_world()->get_width());
    y_pos = float(rand() % WorldObj::get_world()->get_height());

    x_add = static_cast<float>(rand() % 5) + 1.0f;
    y_add = 0.0f;
}
    void UpdateAI(const uint32 diff)
    {
        //Return since we have no target
        if (!UpdateVictim())
            return;

        //Frostbolt
        if (Frostbolt_Timer < diff)
        {
            if (rand()%100 < 90)
                DoCast(m_creature->getVictim(),SPELL_FROSTBOLT);
            Frostbolt_Timer = 3500;
        } else Frostbolt_Timer -= diff;

        //IceTomb
        if (IceTomb_Timer < diff)
        {
            if (rand()%100 < 65)
                DoCast(m_creature->getVictim(),SPELL_ICETOMB);
            IceTomb_Timer = 28000;
        } else IceTomb_Timer -= diff;

        //DrainLife
        if (DrainLife_Timer < diff)
        {
            if (rand()%100 < 55)
                DoCast(m_creature->getVictim(),SPELL_DRAINLIFE);
            DrainLife_Timer = 31000;
        } else DrainLife_Timer -= diff;

        DoMeleeAttackIfReady();
    }