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


C++ randomInt函数代码示例

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


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

示例1: test_by_pict

    virtual void test_by_pict()
    {
        Mat frame1 = readImage("optflow/RubberWhale1.png", IMREAD_GRAYSCALE);

        UMat usrc;
        frame1.copyTo(usrc);
        int histSize = randomInt(3, 29);
        float hue_range[] = { 0, 180 };
        const float* ranges1 = { hue_range };
        Mat hist1;

        //compute histogram
        calcHist(&frame1, 1, 0, Mat(), hist1, 1, &histSize, &ranges1, true, false);
        normalize(hist1, hist1, 0, 255, NORM_MINMAX, -1, Mat());

        Mat dst1;
        UMat udst1, src, uhist1;
        hist1.copyTo(uhist1);
        std::vector<UMat> uims;
        uims.push_back(usrc);
        std::vector<float> urngs;
        urngs.push_back(0);
        urngs.push_back(180);
        std::vector<int> chs;
        chs.push_back(0);

        OCL_OFF(calcBackProject(&frame1, 1, 0, hist1, dst1, &ranges1, 1, true));
        OCL_ON(calcBackProject(uims, chs, uhist1, udst1, urngs, 1.0));
        EXPECT_MAT_NEAR(dst1, udst1, 0.0);
    }
开发者ID:HanaLeeHn,项目名称:opencv,代码行数:30,代码来源:test_histogram.cpp

示例2: checkPickupDrop

void Aircraft::checkPickupDrop(CommandQueue& commands)
{
	if (!isAllied() && randomInt(3) == 0 && !mSpawnedPickup)
		commands.push(mDropPickupCommand);

	mSpawnedPickup = true;
}
开发者ID:Astalto,项目名称:SFMLAssignment2,代码行数:7,代码来源:Aircraft.cpp

示例3: lela_check

uint32 MersenneTwister::randomIntRange (uint32 start, uint32 end) 
{
	lela_check (end > start);

	uint32 dist = end - start;
	uint32 random;

	/* All tricks doing modulo calculations do not have a perfect
	 * distribution -> We must use the slower way through gdouble for
	 * maximal quality. */
   
	if (dist <= 0x10000L) { /* 2^16 */
		/* This method, which only calls g_rand_int once is only good
		 * for (end - begin) <= 2^16, because we only have 32 bits set
		 * from the one call to g_rand_int (). */

		/* we are using (trans + trans * trans), because g_rand_int only
		 * covers [0..2^32-1] and thus g_rand_int * trans only covers
		 * [0..1-2^-32], but the biggest double < 1 is 1-2^-52. 
		 */

		double double_rand =
			randomInt () * (doubleTransform + doubleTransform * doubleTransform);
      
		random = (uint32) (double_rand * dist);
	} else {
		/* Now we use g_rand_double_range (), which will set 52 bits for
		   us, so that it is safe to round and still get a decent
		   distribution */
		random = (uint32) randomDoubleRange (0, dist);
	}
 
	return start + random;
}
开发者ID:Singular,项目名称:LELA,代码行数:34,代码来源:mersenne-twister.C

示例4: randomInt

void Pirate::genType()
{
	int t = randomInt(1,100);
	if( t<34 ) type = "dorc";
	else if(t>=34&&t<66) type = "porc";
	else type = "borc";
}
开发者ID:dring1,项目名称:COMP2404,代码行数:7,代码来源:Pirate.cpp

示例5: re

QByteArray SecureRNG::randomPrintable(int length)
{
    QByteArray re(length, 0);
    for (int i = 0; i < re.size(); i++)
        re[i] = randomInt(95) + 32;
    return re;
}
开发者ID:62gs8ha,项目名称:ricochet,代码行数:7,代码来源:SecureRNG.cpp

示例6: assert

void GeneticPopulation::crossover(
	const Weights& parent1,
	const Weights& parent2,
	Weights& child1,
	Weights& child2) const {

	assert(parent1.size() == parent2.size());

	if (randomReal(0, 1) > crossoverRate || parent1 == parent2) {
		child1 = parent1;
		child2 = parent2;
		return;
	}

	unsigned crossoverPoint = static_cast<unsigned>(randomInt(0, parent1.size()));

	child1.clear();
	child2.clear();

	//create the offspring
	for (unsigned i = 0; i < crossoverPoint; ++i) {
		child1.push_back(parent1[i]);
		child2.push_back(parent2[i]);
	}

	for (unsigned i = crossoverPoint; i < parent1.size(); ++i) {
		child1.push_back(parent2[i]);
		child2.push_back(parent1[i]);
	}
}
开发者ID:matthiasvegh,项目名称:car-game,代码行数:30,代码来源:GeneticPopulation.cpp

示例7: after

KategProblem &makRandom(int ANZ_WORD,int ANZ_CLS,int initValue,
			int auswertung,int nachbarschaft,float relInit)
{
  KategProblem &k=
    *new KategProblem(ANZ_WORD,ANZ_CLS,initValue,auswertung,nachbarschaft);
  KategProblemWBC &w=k.wordFreq;
  Array<int> after(ANZ_WORD,0);
  Array<int> before(ANZ_WORD,0);
  Array<FreqArray> twoD(ANZ_WORD);
	int i;
  for(i=0;i<ANZ_WORD;i++) twoD[i].init(ANZ_WORD,0); 
  
  for(i=0;i<ANZ_WORD;i++)
    {
      massert(after[i]==0);
      massert(before[i]==0);
      for(int j=0;j<ANZ_WORD;j++)
	{
	  massert(twoD[i][j]==0);
	}
    }
  for(i=0;i<ANZ_WORD*ANZ_WORD*relInit;i++)
    {
      int x=randomInt(ANZ_WORD);
      int y=randomInt(ANZ_WORD);
      if(twoD[x][y]==0)
	{
	  after[x]++;
	  before[y]++;
	}
      twoD[x][y]+=randomInt(10)+1;
    }
  for(i=0;i<ANZ_WORD;i++)
    {
      w.setAfterWords(i,after[i]);
      w.setBeforeWords(i,before[i]);
    }
  
  for(i=0;i<ANZ_WORD;i++)
    {
      for(int j=0;j<ANZ_WORD;j++)
	if( twoD[i][j] )
	    w.setFreq(i,j,twoD[i][j]);
    }
  w.testFull();
  return k;
}
开发者ID:51303014,项目名称:giza-pp,代码行数:47,代码来源:KategProblemTest.cpp

示例8: QPoint

void KruskalMaze::generate()
{
	// Generate sets
	m_set_ids = QVector< QVector<Set*> >(columns(), QVector<Set*>(rows()));
	for (int c = 0; c < columns(); ++c) {
		for (int r = 0; r < rows(); ++r) {
			m_sets.append(QList<QPoint>() << QPoint(c, r));
			m_set_ids[c][r] = &m_sets.last();
		}
	}

	while (m_sets.size() > 1) {
		Set* set1 = &m_sets.first();

		// Find random cell
		const QPoint& cell = set1->at(randomInt(set1->size()));

		// Find random neighbor of cell
		QPoint cell2(cell);
		if (randomInt(2)) {
			cell2.rx()++;
		} else {
			cell2.ry()++;
		}
		if (cell2.x() >= columns() || cell2.y() >= rows()) {
			continue;
		}

		// Find set containing second cell
		Set* set2 = m_set_ids.at(cell2.x()).at(cell2.y());

		// Merge sets if they are different
		if (set1 != set2) {
			mergeCells(cell, cell2);
			int size = set1->size();
			for (int i = 0; i < size; ++i) {
				const QPoint& cell3 = set1->at(i);
				m_set_ids[cell3.x()][cell3.y()] = set2;
			}
			*set2 += *set1;
			m_sets.removeFirst();
		}
	}

	m_sets.clear();
	m_set_ids.clear();
}
开发者ID:gottcode,项目名称:cutemaze,代码行数:47,代码来源:maze.cpp

示例9: randomInt

void MainWindow::startGrid()
{
    int i,j,k,l;
    score = 0;
    max = 0;
    for( i=0;i<4;i++ )
        for( j=0;j<4;j++ )
            grid[i][j] = 0;
    i = randomInt(4);
    j = randomInt(4);
    grid[i][j] = 2;
    do{
        k = randomInt(4);
        l = randomInt(4);
    }while( k==i && l==j);
    grid[k][l] = 2;
}
开发者ID:a0952866367,项目名称:2048,代码行数:17,代码来源:mainwindow.cpp

示例10: createMat

    GpuMat createMat(Size size, int type, bool useRoi)
    {
        Size size0 = size;

        if (useRoi)
        {
            size0.width += randomInt(5, 15);
            size0.height += randomInt(5, 15);
        }

        GpuMat d_m(size0, type);

        if (size0 != size)
            d_m = d_m(Rect((size0.width - size.width) / 2, (size0.height - size.height) / 2, size.width, size.height));

        return d_m;
    }
开发者ID:12rohanb,项目名称:opencv,代码行数:17,代码来源:cuda_test.cpp

示例11: render

void
render(SDL_Renderer *renderer)
{
    Uint8 r, g, b;
    int renderW;
    int renderH;

    SDL_RenderGetLogicalSize(renderer, &renderW, &renderH);

    /*  Come up with a random rectangle */
    SDL_Rect rect;
    rect.w = randomInt(64, 128);
    rect.h = randomInt(64, 128);
    rect.x = randomInt(0, renderW);
    rect.y = randomInt(0, renderH);

    /* Come up with a random color */
    r = randomInt(50, 255);
    g = randomInt(50, 255);
    b = randomInt(50, 255);

    /*  Fill the rectangle in the color */
    SDL_SetRenderDrawColor(renderer, r, g, b, 255);
    SDL_RenderFillRect(renderer, &rect);

    /* update screen */
    SDL_RenderPresent(renderer);
}
开发者ID:0-wiz-0,项目名称:mame,代码行数:28,代码来源:rectangles.c

示例12: render

void
render(SDL_Renderer *renderer)
{

    Uint8 r, g, b;

    /* Clear the screen */
    SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
    SDL_RenderClear(renderer);

    /*  Come up with a random rectangle */
    SDL_Rect rect;
    rect.w = randomInt(64, 128);
    rect.h = randomInt(64, 128);
    rect.x = randomInt(0, SCREEN_WIDTH);
    rect.y = randomInt(0, SCREEN_HEIGHT);

    /* Come up with a random color */
    r = randomInt(50, 255);
    g = randomInt(50, 255);
    b = randomInt(50, 255);
    SDL_SetRenderDrawColor(renderer, r, g, b, 255);

    /*  Fill the rectangle in the color */
    SDL_RenderFillRect(renderer, &rect);

    /* update screen */
    SDL_RenderPresent(renderer);
}
开发者ID:0-wiz-0,项目名称:mame,代码行数:29,代码来源:main.c

示例13: randomInts

        static std::vector<int> randomInts(int howMany, int min, int max) {
            std::vector<int> ints;

            for (int index = 0; index < howMany; index++) {
                ints.push_back(randomInt(min, max));
            }

            return ints;
        }
开发者ID:brianherman,项目名称:al2,代码行数:9,代码来源:Utils.hpp

示例14: initPopulation

static void initPopulation() {

    int cromosomeIdx;
    int blocks;
    int threads;

    for (cromosomeIdx = 0; cromosomeIdx < POPULATION_NMR; ++cromosomeIdx) {
        
        do {
            blocks = randomInt(columns - 1) + 1;
            threads = randomInt(columns - 1) + 1;
        } while (2l * blocks * threads >= (long) columns 
            || threads > MAX_THREADS || blocks > MAX_BLOCKS);

        population[cromosomeIdx].blocks = blocks;
        population[cromosomeIdx].threads = threads;
    }
}
开发者ID:brahle,项目名称:swSharp,代码行数:18,代码来源:sw_gpu_param_search.c

示例15: checkPickupDrop

void Tile::checkPickupDrop(CommandQueue& commands)
{
	// Drop pickup, if enemy airplane, with probability 1/4, if pickup not yet dropped
	// and if not in network mode (where pickups are dropped via packets)
	if (isBlock() && randomInt(5) == 0 && !mSpawnedPickup && mPickupsEnabled){
		commands.push(mDropPickupCommand);
	}
	mSpawnedPickup = true;
}
开发者ID:ffrujeri,项目名称:SFML-bomberman-clone,代码行数:9,代码来源:Tile.cpp


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