• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ randInt函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: randFloat

void TestCanvas::testQuadBezier(GiCanvas* canvas, int n)
{
    float x1 = randFloat(100.f, 400.f);
    float y1 = randFloat(100.f, 400.f);
    
    for (int i = 0; i < n; i++) {
        canvas->beginPath();
        
        float x2 = x1 + randFloat(-100.f, 100.f);
        float y2 = y1 + randFloat(-100.f, 100.f);
        float x3 = x2 + randFloat(-100.f, 100.f);
        float y3 = y2 + randFloat(-100.f, 100.f);
        
        canvas->moveTo(x1, y1);
        canvas->lineTo((x1 + x2) / 2, (y1 + y2) / 2);
        
        for (int j = randInt(5, 20); j > 0; j--) {
            canvas->quadTo(x2, y2, (x3 + x2) / 2, (y3 + y2) / 2);
            
            x1 = x2; x2 = x3;
            y1 = y2; y2 = y3;
            x3 = x2 + randFloat(-100.f, 100.f);
            y3 = y2 + randFloat(-100.f, 100.f);
        }
        canvas->lineTo(x2, y2);
        
        if (s_randStyle) {
            canvas->setPen(0xFF000000 | randInt(0, 0xFFFFFF), randFloat(0, 6), randInt(0, 4), 0);
        }
        canvas->drawPath(true, false);
    }
}
开发者ID:gkrists,项目名称:TouchVG,代码行数:32,代码来源:testcanvas.cpp


示例2: KSprite

/*! \class KRock
  \brief Class KRock is the base class for three sizes of rock.

  The rock base class generates and holds some random values
  used when computing the next image to display. This makes
  the rocks look like they are tumbling.

  The static count of rocks created is incremented.
  \internal
 */
KRock::KRock() : KSprite()
{
    skip_ = randInt(2);
    cskip_ = skip_;
    step_ = randInt(2) ? -1 : 1;
    ++rocksCreated_;
    allRocksDestroyed_ = false;
}
开发者ID:Camelek,项目名称:qtmoko,代码行数:18,代码来源:sprites.cpp


示例3: randFloat

void TestCanvas::testEllipse(GiCanvas* canvas)
{
    for (int i = 0; i < 100; i++) {
        canvas->drawEllipse(randFloat(10.f, 600.f), randFloat(10.f, 600.f),
                            randFloat(10.f, 400.f), randFloat(10.f, 400.f),
                            randInt(0, 1) == 1, randInt(0, 1) == 1);
    }
}
开发者ID:huangzongwu,项目名称:vglite,代码行数:8,代码来源:testcanvas.cpp


示例4: Snakewomen

Snakewomen:: Snakewomen (int r, int c, char name, string full_name, Pit* p) : Monster(r,c,name, full_name,p)
{
    set_Hit_points(randInt(4)+3);//Hp is between 3-6
    set_stregth_points(2); //strength is between 2
    set_desterity(6);// set desterity between 3;
    set_armor_points(2);//set armor to 2;
	set_damage_point(randInt(return_strength_points() + 2));
    set_weapon_wielding("magicfangsofsleep");
 
}
开发者ID:taoxiang1995,项目名称:mini-Rogue,代码行数:10,代码来源:Snakewomen.cpp


示例5: randInt

void TestCanvas::testLine(GiCanvas* canvas, int n)
{
    for (int i = 0; i < n; i++) {
        if (s_randStyle) {
            canvas->setPen(randInt(10, 0xFF) << 24 | randInt(0, 0xFFFFFF), -1.f, -1, 0);
        }
        canvas->drawLine(randFloat(10.f, 600.f), randFloat(10.f, 600.f),
                        randFloat(10.f, 400.f), randFloat(10.f, 400.f));
    }
}
开发者ID:rhcad,项目名称:vglite,代码行数:10,代码来源:testcanvas.cpp


示例6: KFragment

/*!
  A private function that explodes the ship into a number of
  ship \l {KFragment} {fragments}.
 */
void KShip::explode()
{
    KFragment* f;
    for (int i=0; i<8; i++) {
	f = new KFragment();
	f->setPos((x()+5) - (randDouble()*10), (y()+5) - (randDouble()*10));
	f->setImage(randInt(FRAG_IMAGE_COUNT));
	f->setVelocity(1 - (randDouble()*2), 1 - (randDouble()*2));
	f->setMaximumAge(60 + randInt(60));
	f->show();
    }
}
开发者ID:Camelek,项目名称:qtmoko,代码行数:16,代码来源:sprites.cpp


示例7: updateFalling

void updateFalling(void)
{
	for(int j=0; j<numberOfFalling; j++)
		{
			if(moving[j].use==true)
				{
					swirlingDirection=randInt(MAXSWIRL);
					if(randomEvent(2)==true)
						swirlingDirection=-swirlingDirection;
					moving[j].stepX=moving[j].stepX+swirlingDirection;
					if(moving[j].stepX>maxXStep)
						moving[j].stepX=maxXStep;
					if(moving[j].stepX<-maxXStep)
						moving[j].stepX=-maxXStep;

					moving[j].y=moving[j].y+moving[j].stepY;
					moving[j].x=moving[j].x+moving[j].stepX+windSpeed+(gustOffSet*gustDirection);

					if(checkOnWindow(&moving[j])==false)
						{
							if(moving[j].y>displayHeight+moving[j].object->h[0])
								{
									moving[j].use=false;
									moving[j].y=0-moving[j].object->h[0];
									updateBottomSnow(&moving[j]);
								}
						}
					else
						{
							moving[j].use=false;
							moving[j].y=0-moving[j].object->h[0];
						}

					if(moving[j].x>displayWidth+moving[j].object->w[0])
						moving[j].x=0-moving[j].object->w[0];

					if(moving[j].x<0-moving[j].object->w[0])
						moving[j].x=displayWidth;
				}
			else
				{
					if(randomEvent(fallingSpread)==true)
						{
							moving[j].use=true;
							moving[j].stepY=randInt(fallSpeed-minFallSpeed+1)+minFallSpeed;
							moving[j].x=(rand() % displayWidth);
							moving[j].imageNum=randInt(moving[j].object->anims);
							moving[j].countDown=fallingAnimSpeed;
							moving[j].direction=randomEvent(2);
						}
				}
		}
}
开发者ID:KeithDHedger,项目名称:XDecorations,代码行数:53,代码来源:update.cpp


示例8: switch

void Player::attack(Actor* monster){
    
    //check if the function input is acually a monster through dynamic cast
    Monster* temp = dynamic_cast<Monster*>(monster);
    string monsterName;
    char c = temp->getType();
    
    //check the monsters type and based on that, assign monsterName a specific name
    switch (c) {
        case 'S':
            monsterName = " a Snakewoman";
            break;
        case 'B':
            monsterName = " a Boogeyman";
            break;
        case 'D':
            monsterName = " a Dragon";
            break;
        case 'G':
            monsterName = " a Goblin";
            break;
            
        default:
            break;
    }
    
    //check if the players attackerPoints are greater than the monsters defenderPoints
    if (randInt(dexterity() + equiped->dex_bonus) >= randInt(monster->dexterity() + monster->armor())) {
        
        //subtract the inflicted damage from the monster
        monster->setHealth(monster->health() - randInt(strength() + equiped->str_bonus));
        
        //if the user is using MagicFangs and probablilty is greater than 1/3 then put the monster to sleep
        if (equiped->m_name == "Magic fangs of sleep") {
            if(trueWithProbability(.3)){
                monster->setSleep(2+randInt(5));
                //add an action to action vector
                dungeon()->action_vector.push_back("Player" + equiped->action() + monsterName+" and puts him to sleep.");
            }
            else
                //add an action saying that the player hit but did not put to sleep
                dungeon()->action_vector.push_back("Player" + equiped->action()  +monsterName + " and hits.");
        }
        else
            //add an action saying that the player hit
            dungeon()->action_vector.push_back("Player" + equiped->action()  +monsterName + " and hits.");
    }
    else
        //add an action saying that the player missed
        dungeon()->action_vector.push_back("Player" + equiped->action() + monsterName+ " and misses.");

}
开发者ID:Garchbold,项目名称:minirogue,代码行数:52,代码来源:Player.cpp


示例9: randInt

void ParticlePool::spark(Position &pos)
{
	int numParticles = randInt(3,6);
	
	for(int ii=0; ii<numParticles; ii++)
	{
		Position particlePos(pos);
		particlePos.impulse( randFloat(-50, 50), randFloat(-50, 50) );
		float whiteness = randInt(0, 255);
		Particle p = Particle(whiteness, whiteness, 255, randInt(170, 255), 0.15, particlePos, 300);
		add(p);
	}
}
开发者ID:yixu34,项目名称:Mastrix,代码行数:13,代码来源:particlepool.cpp


示例10: getLocation

void Spider::doSomething()
{
	if(restNow)
	{
		restNow=false; //rest every other tick
		return;
	}

	int x, y;
	getLocation(x, y); //get its current location

	if(m_distance==0) //if its distance is 0, flip its vertical direction and select a new distance
	{
		if(!movingDown) //if moving up
		{
			movingDown=true;	
			m_distance=randInt(1, y-1);
		}
		else //if moving down
		{
			movingDown=false;
			m_distance=randInt(1, GARDEN_HEIGHT-y-1);
		}
	}

	int newx, newy; //calculate the new diagonal location
	
	if(movingDown)
		newy=y-1;
	else
		newy=y+1;

	if(movingRight)
		newx=x+1;
	else
		newx=x-1;

	m_distance--; //decrement its vertical direction

	if(getWorld()->mushroomThere(newx, newy))
		getWorld()->removeMushroom(newx, newy); //if there is a mushroom, remove it

	if(newx<0 || newx>=GARDEN_WIDTH || newy<0 || newy>=GARDEN_HEIGHT) //if it moves out of bounds, set it to dead
		setDead();
	else
		moveTo(newx, newy); //move the spider

	getWorld()->killPlayer(newx, newy); //if it lands on player, kill it

	restNow=true; //if it didn't rest this tick, next tick it will rest
}
开发者ID:kerrywang,项目名称:UCLA-CS-32,代码行数:51,代码来源:actor.cpp


示例11: randAllele

// do the Allele selection
int randAllele(int numMom, int numDad, float selection) {
	if ((numMom == 0) && (numDad == 0)) {
		return 0;
	}
	else if ((numMom == 1) && (numDad == 0)) {
		return randInt(2);
	}
	else if ((numMom == 2) && (numDad == 0)) {
		return 1;
	}
	else if ((numMom == 0) && (numDad == 1)) {
		return randInt(2);
	}
	else if ((numMom == 1) && (numDad == 1)) {
		float val = randRange(0,(3+selection));
		if (val < 1.0) {
			return 0;
		}
		else if (val < 3.0) {
			return 1;
		}
		else {
			return 2;
		}
	}
	else if ((numMom == 2) && (numDad == 1)) {
		float val = randRange(0,(1+selection));
		if (val < 1.0) {
			return 1;
		}
		else {
			return 2;
		}
	}
	else if ((numMom == 0) && (numDad == 2)) {
		return 1;
	}
	else if ((numMom == 1) && (numDad == 2)) {
		float val = randRange(0,(1+selection));
		if (val < 1.0) {
			return 1;
		}
		else {
			return 2;
		}
	}
	else if ((numMom == 2) && (numDad == 2)) {
		return 2;
	}
}
开发者ID:jxchong,项目名称:genedropping,代码行数:51,代码来源:GeneDroppingCohorts.c


示例12: randInt

void CadMdiChild::on_addCircles_clicked() {
    auto builder = std::make_shared<lc::operation::Builder>(document());
    auto layer = _storageManager->layerByName("0");

    for (int i = 0; i < 1000; i++) {
        double x1 = randInt(-4000, 4000);
        double y1 = randInt(-4000, 4000);

        double r = randInt(0, 150);
        builder->append(std::make_shared<lc::Circle>(lc::geo::Coordinate(x1, y1), r, layer));
    }

    builder->execute();
}
开发者ID:jasvir99,项目名称:LibreCAD_3,代码行数:14,代码来源:cadmdichild.cpp


示例13: randInt

void GameObjects::initializeSpot()
{
	int r = 1 + randInt(LEVEL_ROWS - 1);
	int c = 1 + randInt(LEVEL_COLS - 1);
	if (m_dungeon->noWalls(r, c) && (m_dungeon->noWalls(r, c - 1) || m_dungeon->noWalls(r, c + 1))
		&& (m_dungeon->noWalls(r - 1, c) || m_dungeon->noWalls(r + 1, c)))
	{
		m_row = r;
		m_col = c;
	}
	else
		initializeSpot();
	return;
}
开发者ID:mariecuriosity,项目名称:cs32,代码行数:14,代码来源:GameObjects.cpp


示例14: qsrand

/** Sets a random position to the player */
void Player::randompos()
{
    QTime time = QTime::currentTime();
    qsrand((uint)time.msec());

    QThread::msleep(10);

    int p = randInt(2,WIDTH-2);

    int p2 = randInt(2,HEIGHT-2);

    pX = p;
    pY = p2;
}
开发者ID:gaissa,项目名称:Darkfield,代码行数:15,代码来源:player.cpp


示例15: generateFile

void generateFile(char *path, long size, int minKeyValue, int maxKeyValue, int minValLen, int maxValLen) {
    srand(time(NULL));
    FILE *file = fopen(path, "w");
    long i;
    int next;
    fprintf(file, "%ld\n", size);
    for (i = 0; i < size; i++) {
        next = randInt(minKeyValue, maxKeyValue);
        int len = randInt(minValLen, maxValLen);
        char *value = randStr(len);
        fprintf(file, "%d %s\n", next, value);
        free(value);
    }
    fclose(file);
}
开发者ID:AlphaBeth,项目名称:ITMO,代码行数:15,代码来源:utils.cpp


示例16: randFloat

 float randFloat(float min,float max)
 {
    if (min==max)
       return min;
    return ( (float)(randInt( (int)min, (int)max)) +
       ((float)rand() / ((float)RAND_MAX + 1)));
 }
开发者ID:spearmunkie,项目名称:chain-physics,代码行数:7,代码来源:mathUtils.cpp


示例17: randInt

Color Utility::randColor()
{
    int color = randInt(6, false)+1;

    if(color == 1)
    {
        return Color::Yellow;
    }
    else if(color == 2)
    {
        return Color::Red;
    }
    else if(color == 3)
    {
        return Color::Green;
    }
    else if(color == 4)
    {
        return Color::Cyan;
    }
    else if(color == 5)
    {
        return Color::Magenta;
    }

    return Color::Blue;
}
开发者ID:zimzim62000,项目名称:TryToFolowMe,代码行数:27,代码来源:Utility.cpp


示例18: test

int test(int testC)
{
	char testString[] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
	srand(time(NULL));
	char searchedChar;
	int charIndex;
	int arrowPos;

	printf("Find rightmost occurence of characters in this text:\n %s\n\n", testString);
	int i;
	for (i = 0; i < testC; i++) {
		searchedChar = randInt('a', 'z');
		printf("?  %c\n", searchedChar);
		charIndex = searchChar(searchedChar, testString);
		if (charIndex != -1) {
			arrowPos = printfExcerpt(testString, OUTBUFFERWIDTH, charIndex);
			printf("\n");
			for (; arrowPos > 0; arrowPos--) {
				printf(" ");
			}
			printf("^\n");
		} else {
			printf("Not found\n");
		}
	}
	return 0;
}
开发者ID:lleaff,项目名称:Ctests,代码行数:27,代码来源:searchChar.c


示例19: main

int main()
{
    uart_init();
    char in[40]; // input buffer
    while(1)
    {
        if(!gameStarted) 
            intro();
        unsigned int theGuess = randInt(lowerBound, upperBound);
        guess(theGuess);
        read_echo(in);
        if(in[0] == 'h')
            lowerBound = theGuess;
        else if(in[0] == 'l')
            upperBound = theGuess;
        else if(in[0] == 'y')
        {
            printLine("I win");
            gameStarted = 0;
            printLine("press any key to continue...");
            uart_receive();
        }
        else if(isReset(in))
        {
            gameStarted = false;
            printLine("press any key to continue...");
            uart_receive();
        }
   }
}
开发者ID:dangarbri,项目名称:atmega644,代码行数:30,代码来源:serial.c


示例20: hashTableInitAllKeys

static void hashTableInitAllKeys(hashTableType *table, handType *hand, int ranks[NUM_RANKS], int curRank) {
	// initially choose a random response for AI
	unsigned long int response = 0;
	for (int i = 0; i < NUM_APPRECIABLE_RANKS; i++)
		response = response * 10 + randInt(0,1);

	hashTableInsert(table, hand, response);

	if (ranks[curRank] >= NUM_SUITS) {
		curRank += 1;
	}

	for (int i = curRank; i < NUM_APPRECIABLE_RANKS; i++) {
		hand->cards[hand->handSize].rank = i;
		hand->handSize += 1;
		ranks[i] += 1;

		handFindSum(hand);
		if (hand->sum > 21) {
			hand->handSize -= 1;
			ranks[i] -=1;
			break;
		}

		hashTableInitAllKeys(table, hand, ranks, i);

		hand->handSize -= 1;
		ranks[i] -= 1;
	}
}
开发者ID:JamesonWeng,项目名称:Blackjack-AI,代码行数:30,代码来源:hashtable.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ rand_bytes函数代码示例发布时间:2022-05-30
下一篇:
C++ randFloat函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap