当前位置: 首页>>代码示例>>C++>>正文


C++ random_range函数代码示例

本文整理汇总了C++中random_range函数的典型用法代码示例。如果您正苦于以下问题:C++ random_range函数的具体用法?C++ random_range怎么用?C++ random_range使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了random_range函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: update

void update(float percent, float offset)
{
	int n = (int) (position_counter * percent / 100);
	for (int j = 0; j < n; j++) {
		int i = (int) random_range(0, position_counter - 1);
		float x = position_matrix[i].x + random_range(- offset, offset);
		float y = position_matrix[i].y + random_range(- offset, offset);
		position_matrix[i].x = (x <= 0) ? 0 : (x <= 1) ? x : 1;
		position_matrix[i].y = (y <= 0) ? 0 : (y <= 1) ? y : 1;
	}
}
开发者ID:mgmalheiros,项目名称:spatial-sorting,代码行数:11,代码来源:test-1-full-sort.cpp

示例2: straggle_corridor

void straggle_corridor(int fx, int fy, int tx, int ty, Symbol loc, char rsi)
{
  int dx,dy;
  while ((fx != tx) || (fy != ty)) {
    dx = tx - fx;
    dy = ty - fy;
    if (random_range(abs(dx)+abs(dy)) < abs(dx))
      corridor_crawl(&fx,&fy,sign(dx),0,random_range(abs(dx))+1,loc,rsi);
    else corridor_crawl(&fx,&fy,0,sign(dy),random_range(abs(dy))+1,loc,rsi);
  }
}
开发者ID:anylonen,项目名称:omega,代码行数:11,代码来源:gen1.c

示例3: int32_t

int32_t WeaponMelee::getElementDamage(const Player* player, const Item* item) const
{
	int32_t attackSkill = player->getWeaponSkill(item);
	int32_t attackValue = std::max<int32_t>(0, elementDamage);
	float attackFactor = player->getAttackFactor();

	int32_t maxValue = Weapons::getMaxWeaponDamage(player->getLevel(), attackSkill, attackValue, attackFactor);
	if(random_range(1, 100) <= g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE))
		maxValue <<= 1;

	maxValue = int32_t(maxValue * player->getVocation()->meleeDamageMultipler);
	return -random_range(0, maxValue, DISTRO_NORMAL);
}
开发者ID:CkyLua,项目名称:tfs,代码行数:13,代码来源:weapons.cpp

示例4: i_chaos

void i_chaos(pob o)
{
  if (Player.alignment < 0) {
    Player.alignment -= random_range(20);
    mprint("You feel deliciously chaotic!");
    gain_experience(abs(Player.alignment)*10);
  }
  else {
    mprint("You feel a sense of inner turmoil!");
  }
  /* Potion of Chaos always makes player more chaotic. PGM */
  Player.alignment -= random_range(20);
}
开发者ID:anylonen,项目名称:omega,代码行数:13,代码来源:effect2.c

示例5: itemblessing

int itemblessing(void)
{
    switch(random_range(10)) {
    case 0:
    case 1:
        return(-1-random_range(10));
    case 8:
    case 9:
        return(1+random_range(10));
    default:
        return(0);
    }
}
开发者ID:cwc,项目名称:OmegaRPG,代码行数:13,代码来源:item.cpp

示例6: i_law

void i_law(pob o)
{
  if (Player.alignment > 0) {
    Player.alignment += random_range(20);
    mprint("You feel wonderfully lawful!");
    gain_experience(Player.alignment*10);
  }
  else {
    mprint("You feel a sense of inner constraint!");
  }
  /* Potion of Law always makes player more lawful. PGM */
  Player.alignment += random_range(20);
}
开发者ID:anylonen,项目名称:omega,代码行数:13,代码来源:effect2.c

示例7: random_range

bool Spawn::spawnMonster(uint32_t spawnId, MonsterType* mType, const Position& pos, Direction dir, bool startup /*= false*/)
{
	int32_t nHealth = mType->health,nMaxHealth = mType->healthMax, nExp = mType->experience, nDef = mType->defense, nArm = mType->armor;
		int32_t monsterLevel = random_range(mType->minLevel, mType->maxLevel);
	if (monsterLevel != 0)
	{
    monsterLevel = monsterLevel;
} else {
    monsterLevel = random_range(5,15);
}
	mType->health = (uint64_t)std::ceil(mType->health * monsterLevel / 8);
	mType->healthMax = (uint64_t)std::ceil(mType->healthMax * monsterLevel / 8);
	mType->experience = (uint64_t)std::ceil(mType->experience * monsterLevel / 8);
	mType->defense = (uint64_t)std::ceil(mType->defense * monsterLevel / 8);
	mType->armor = (uint64_t)std::ceil(mType->armor * monsterLevel / 8);
    Monster* monster = Monster::createMonster(mType);
    monster->doMonsterSetCombatValues(monsterLevel);
    monster->doMonsterSetLevel(monsterLevel);
 
mType->health = nHealth;
mType->healthMax = nMaxHealth;
mType->experience = nExp;
mType->defense = nDef;
mType->armor = nArm;
	if(!monster)
		return false;

	if(startup)
	{
		//No need to send out events to the surrounding since there is no one out there to listen!
		if(!g_game.internalPlaceCreature(monster, pos, false, true))
		{
			delete monster;
			return false;
		}
	}
	else if(!g_game.placeCreature(monster, pos, false, true))
	{
		delete monster;
		return false;
	}

	monster->setSpawn(this);
	monster->setMasterPosition(pos, radius);
	monster->setDirection(dir);

	monster->addRef();
	spawnedMap.insert(SpawnedPair(spawnId, monster));
	spawnMap[spawnId].lastSpawn = OTSYS_TIME();
	return true;
}
开发者ID:AhmedWaly,项目名称:LiveCast,代码行数:51,代码来源:spawn.cpp

示例8: vector_random_direction

Vector vector_random_direction(void)
{
    float x, y, z;

    do
    {
        x = random_range(-1, 1);
        y = random_range(-1, 1);
        z = random_range(-1, 1);
    }
    while (x*x + y*y + z*z > 1);

    return vector_normalize(vector(x, y, z));
}
开发者ID:clyde7,项目名称:iv,代码行数:14,代码来源:vector.c

示例9: make_weapon

void make_weapon(Object* newObject, int id)
{
    if (id == -1) id = random_range(NUMWEAPONS);
    *newObject = Objects[WEAPONID+id];
    if ((id == 28) || (id == 29)) /* bolt or arrow */
        newObject->number = random_range(20)+1;
    if (newObject->blessing == 0) newObject->blessing = itemblessing();
    if (newObject->plus == 0) {
        newObject->plus = itemplus();
        if (newObject->blessing < 0)
            newObject->plus = -1 - abs(newObject->plus);
        else if (newObject->blessing > 0)
            newObject->plus = 1 + abs(newObject->plus);
    }
}
开发者ID:cwc,项目名称:OmegaRPG,代码行数:15,代码来源:item.cpp

示例10: setTicks

bool ConditionDamage::init()
{
	if(periodDamage != 0){
		return true;
	}

	if(damageList.empty()){
		setTicks(0);

		int32_t amount = random_range(minDamage, maxDamage);

		if(amount != 0){
			if(startDamage > maxDamage){
				startDamage = maxDamage;
			}
			else if(startDamage == 0){
				startDamage = std::max((int32_t)1, (int32_t)std::ceil(((float)amount / 20.0)));
			}

			std::list<int32_t> list;
			ConditionDamage::generateDamageList(amount, startDamage, list);

			for(std::list<int32_t>::iterator it = list.begin(); it != list.end(); ++it){
				addDamage(1, tickInterval, -*it);
			}
		}
	}

	return (!damageList.empty());
}
开发者ID:gianflogao,项目名称:divinity-ots,代码行数:30,代码来源:condition.cpp

示例11: searchat

/* search once particular spot */
void searchat(int x, int y)
{
    int i;
    if (inbounds(x,y) && (random_range(3) || Player.status[ALERT])) {
        if (loc_statusp(x,y,SECRET)) {
            lreset(x,y,SECRET);
            lset(x, y, CHANGED);
            if ((Level->site[x][y].locchar==OPEN_DOOR) ||
                    (Level->site[x][y].locchar==CLOSED_DOOR)) {
                mprint("You find a secret door!");
                for(i=0; i<=8; i++) { /* FIXED! 12/25/98 */
                    lset(x+Dirs[0][i],y+Dirs[1][i],STOPS);
                    lset(x+Dirs[0][i], y+Dirs[1][i], CHANGED);
                }
            }
            else mprint("You find a secret passage!");
            drawvision(Player.x,Player.y);
        }
        if ((Level->site[x][y].p_locf >= TRAP_BASE) &&
                (Level->site[x][y].locchar != TRAP) &&
                (Level->site[x][y].p_locf <= TRAP_BASE+NUMTRAPS)) {
            Level->site[x][y].locchar = TRAP;
            lset(x, y, CHANGED);
            mprint("You find a trap!");
            drawvision(Player.x,Player.y);
            State.setFastMove(false);
        }
    }
}
开发者ID:Geozop,项目名称:OmegaRPG,代码行数:30,代码来源:aux1.cpp

示例12: gain_level

/* Increase in level at appropriate experience gain */
void gain_level(void)
{
  int gained=FALSE;
  int hp_gain; /* FIXED! 12/30/98 */
  
  if (gamestatusp(SUPPRESS_PRINTING))
    return;
  while (expval(Player.level+1) <= Player.xp) {
    if (!gained)
      morewait();
    gained = TRUE;
    Player.level++;
    print1("You have attained a new experience level!");
    print2("You are now ");
    nprint2(getarticle(levelname(Player.level)));
    nprint2(levelname(Player.level));
    hp_gain = random_range(Player.con)+1; /* start fix 12/30/98 */
    if (Player.hp < Player.maxhp )
      Player.hp += hp_gain*Player.hp/Player.maxhp;
    else if (Player.hp < Player.maxhp + hp_gain)
      Player.hp = Player.maxhp + hp_gain;
    /* else leave current hp alone */
    Player.maxhp += hp_gain;
    Player.maxmana = calcmana();
    /* If the character was given a bonus, let him keep it.  Otherwise
     * recharge him. */
    Player.mana = max(Player.mana, Player.maxmana); /* end fix 12/30/98 */
    morewait();
  }
  if (gained) clearmsg();
  calc_melee();
}
开发者ID:anylonen,项目名称:omega,代码行数:33,代码来源:aux2.c

示例13: setTicks

bool ConditionDamage::init()
{
	if(periodDamage)
		return true;

	if(!damageList.empty())
		return true;

	setTicks(0);
	int32_t amount = random_range(minDamage, maxDamage);
	if(!amount)
		return false;

	if(startDamage > maxDamage)
		startDamage = maxDamage;
	else if(!startDamage)
		startDamage = std::max((int32_t)1, (int32_t)std::ceil(((float)amount / 20.0)));

	std::list<int32_t> list;
	ConditionDamage::generateDamageList(amount, startDamage, list);
	for(std::list<int32_t>::iterator it = list.begin(); it != list.end(); ++it)
		addDamage(1, tickInterval, -(*it));

	return !damageList.empty();
}
开发者ID:Codex-NG,项目名称:thecrystalserver,代码行数:25,代码来源:condition.cpp

示例14: if

const char* object_generator::get_value(unsigned long long key_index, unsigned int *len) {
    // compute size
    unsigned int new_size = 0;
    if (m_data_size_type == data_size_fixed) {
        new_size = m_data_size.size_fixed;
    } else if (m_data_size_type == data_size_range) {
        if (m_data_size_pattern && *m_data_size_pattern=='S') {
            double a = (key_index-m_key_min)/static_cast<double>(m_key_max-m_key_min);
            new_size = (m_data_size.size_range.size_max-m_data_size.size_range.size_min)*a + m_data_size.size_range.size_min;
        } else {
            new_size = random_range(m_data_size.size_range.size_min > 0 ? m_data_size.size_range.size_min : 1,
                                    m_data_size.size_range.size_max);
        }
    } else if (m_data_size_type == data_size_weighted) {
        new_size = m_data_size.size_list->get_next_size();
    } else {
        assert(0);
    }

    // modify object content in case of random data
    if (m_random_data) {
        m_value_buffer[m_value_buffer_mutation_pos++]++;
        if (m_value_buffer_mutation_pos >= m_value_buffer_size)
            m_value_buffer_mutation_pos = 0;
    }

    *len = new_size;
    return m_value_buffer;
}
开发者ID:oranagra,项目名称:memtier_benchmark,代码行数:29,代码来源:obj_gen.cpp

示例15: onThinkTarget

void Actor::onThinkTarget(uint32_t interval)
{
  if(!isSummon()){
    if(cType.changeTargetSpeed() > 0){
      bool canChangeTarget = true;
      if(targetChangeCooldown > 0){
        targetChangeCooldown -= interval;
        if(targetChangeCooldown <= 0){
          targetChangeCooldown = 0;
          targetChangeTicks = (uint32_t)cType.changeTargetSpeed();
        }
        else{
          canChangeTarget = false;
        }
      }

      if(canChangeTarget){
        targetChangeTicks += interval;

        if(targetChangeTicks >= (uint32_t)cType.changeTargetSpeed()){
          targetChangeTicks = 0;
          targetChangeCooldown = (uint32_t)cType.changeTargetSpeed();

          if(cType.changeTargetChance() >= random_range(1, 100)){
            searchTarget(TARGETSEARCH_RANDOM);
          }
        }
      }
    }
  }
}
开发者ID:opentibia,项目名称:server,代码行数:31,代码来源:actor.cpp


注:本文中的random_range函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。