本文整理汇总了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);
}
示例2: checkPickupDrop
void Aircraft::checkPickupDrop(CommandQueue& commands)
{
if (!isAllied() && randomInt(3) == 0 && !mSpawnedPickup)
commands.push(mDropPickupCommand);
mSpawnedPickup = true;
}
示例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;
}
示例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";
}
示例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;
}
示例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]);
}
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
}
示例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;
}