本文整理汇总了C++中Rand::nextInt方法的典型用法代码示例。如果您正苦于以下问题:C++ Rand::nextInt方法的具体用法?C++ Rand::nextInt怎么用?C++ Rand::nextInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rand
的用法示例。
在下文中一共展示了Rand::nextInt方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NextFile
//*************************************************************************
void BeatDetectorApp::NextFile()
{
roto = 0;
if(mTrack && mTrack->isPlaying())
{
mTrack->enablePcmBuffering(false);
mTrack->stop();
}
#ifdef WIN32
time_t now;
time(&now);
int time_int = (int)now;
#else
timeval now;
gettimeofday(&now, NULL);
int time_int = now.tv_sec;
#endif
Rand r;
r.seed(time_int);
int rand_file = r.nextInt(m_FileList.size());
path my_path = m_FileList[rand_file].path();
m_CurrentFile = my_path.string();
if(!write_frames)
{
mAudioSource = audio::load(m_CurrentFile);
mTrack = audio::Output::addTrack(mAudioSource, false);
mTrack->enablePcmBuffering(true);
mTrack->play();
}
//rot_inc = r.nextFloat(1.5f, 30.0f);
}
示例2: keyDown
void EditorState::keyDown(ci::app::KeyEvent event)
{
// XXX duplicate raycast
Vec2f pos = GG.mouse.getPos();
Vec3f planeHit = GG.hexRender.raycastHexPlane(pos.x, pos.y);
HexCoord selectedHex = GG.hexGrid.WorldToHex(planeHit);
int keycode = event.getCode();
Vec3f& cameraTo = GG.hexRender.getCameraTo();
if (keycode == app::KeyEvent::KEY_ESCAPE) {
mManager.setActiveState("title");
}
else if (keycode == app::KeyEvent::KEY_UP) {
cameraTo += Vec3f(0, 2.0f, 0);
}
else if (keycode == app::KeyEvent::KEY_DOWN) {
cameraTo += Vec3f(0, -2.0f, 0);
}
else if (keycode == app::KeyEvent::KEY_LEFT) {
cameraTo += Vec3f(-2.0f, 0, 0);
}
else if (keycode == app::KeyEvent::KEY_RIGHT) {
cameraTo += Vec3f(2.0f, 0, 0);
}
else if (keycode == app::KeyEvent::KEY_g) {
// Generate hex colors
Vec2i mapSize = GG.hexMap.getSize();
for (int iy=0; iy < mapSize.y; ++iy) {
for (int ix=0; ix < mapSize.x; ++ix) {
HexCell& cell = GG.hexMap.at(HexCoord(ix, iy));
if (cell.getLand()) {
int playerID = random.nextInt(0, 5);
cell.setOwner(playerID);
cell.setColor(GG.warGame.getPlayers()[playerID].getColor());
}
}
}
}
else if (keycode == app::KeyEvent::KEY_DELETE) {
GG.hexMap.at(selectedHex).setLand(0);
}
else if (keycode == app::KeyEvent::KEY_SPACE) {
mManager.setActiveState(string("game"));
}
else if (keycode == app::KeyEvent::KEY_c) {
vector<HexCoord> connected = GG.hexMap.connected(selectedHex);
for (vector<HexCoord>::iterator it = connected.begin(); it != connected.end(); ++it) {
HexCell& cell = GG.hexMap.at(*it);
Color cellColor = cell.getColor();
cellColor.r = 0.5f * cellColor.r;
cellColor.g = 0.5f * cellColor.g;
cellColor.b = 0.5f * cellColor.b;
cell.setColor(cellColor);
}
}
}
示例3:
MyCircle::MyCircle(int x, int y, int radius){
this->x_ = x;
this->y_ = y;
this->child_ = NULL;
this->anchor_x_ = x;
this->anchor_y_ = y;
this->bound_ = 0;
this->alpha_level_ = 0;
//make sure the radius isn't too large
if(radius > 100)
this->radius_ = 100;
else
this->radius_ = radius;
//make the shape a random color:
Rand random;
random.seed(x*y);
this->color_ = Color8u(random.nextInt(0,256),
random.nextInt(0,256),random.nextInt(0,256));
this->work_color_ = color_;
}
示例4: triangulate
void triangulate( Rand &prng, Graph &graph )
{
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_2<K> Triangulation;
typedef Triangulation::Edge_iterator Edge_iterator;
typedef Triangulation::Vertex_handle Vertex_handle;
typedef Triangulation::Point Point;
typedef std::map<Vertex_handle, int> VertexIndexMap;
const static int minEdgeWeight = 1;
const static int maxEdgeWeight = 20;
// create the delaunay triangulation
Triangulation triangulation;
VertexIndexMap vertexIndexMap;
// dump all of the BGL vertices into CGAL
Graph::vertices_size_type numVertices = boost::num_vertices( graph );
for ( int idx = 0; idx < numVertices; ++idx )
{
const VertexInfo &vertexInfo = boost::get( VertexInfoTag(), graph, idx );
Point position( vertexInfo.position.x, vertexInfo.position.y );
Vertex_handle handle = triangulation.insert( position );
vertexIndexMap[ handle ] = idx;
}
// edge weight property map
auto edgeWeightMap = boost::get( boost::edge_capacity, graph );
// read out the edges and add them to BGL
EdgeReverseMap edgeReverseMap = boost::get( boost::edge_reverse, graph );
Edge_iterator ei_end = triangulation.edges_end();
for (Edge_iterator ei = triangulation.edges_begin();
ei != ei_end; ++ei)
{
int idxSourceInFace = ( ei->second + 2 ) % 3;
int idxTargetInFace = ( ei->second + 1 ) % 3;
Vertex_handle sourceVertex = ei->first->vertex( idxSourceInFace );
Vertex_handle targetVertex = ei->first->vertex( idxTargetInFace );
int idxSource = vertexIndexMap[ sourceVertex ];
int idxTarget = vertexIndexMap[ targetVertex ];
EdgeHandle forwardEdge = boost::add_edge( idxSource, idxTarget, graph );
EdgeHandle backwardEdge = boost::add_edge( idxTarget, idxSource, graph );
edgeReverseMap[ forwardEdge.first ] = backwardEdge.first;
edgeReverseMap[ backwardEdge.first ] = forwardEdge.first;
int edgeWeight = prng.nextInt( 1, 20 );
edgeWeightMap[ forwardEdge.first ] = edgeWeight;
edgeWeightMap[ backwardEdge.first ] = edgeWeight;
}
}
示例5: getRandDir
int getRandDir (int gridSize, Rand myRand) {
int thisDir = myRand.nextInt(4);
int dirVal = 0;
switch (thisDir) {
case 0:
dirVal = 1;
break;
case 1:
dirVal = -1;
break;
case 2:
dirVal = gridSize;
break;
case 3:
dirVal = -gridSize;
break;
};
return dirVal;
};
示例6: Color
void P_2_1_3_01App::draw()
{
// clear out the window with black
gl::clear( Color( 1, 1, 1 ) );
gl::color(0, 0, 0, 0.5f);
mRand.seed(mRandomSeed);
gl::pushMatrices();
gl::translate(mTileWidth / 2.0f, mTileHeight / 2.0f);
mCircleCount = mMousePos.x / 30.0f + 1.0f;
mEndSize = lmap(float(mMousePos.x), 0.0f, float(getWindowWidth()), mTileWidth / 2.0f, 0.0f);
mEndOffset = lmap(float(mMousePos.y), 0.0f, float(getWindowHeight()), 0.0f, (mTileWidth - mEndSize)/2.0f);
for (int gridY = 0; gridY <= mTileCountY; gridY++) {
for (int gridX = 0; gridX <= mTileCountX; gridX++) {
gl::pushMatrices();
gl::translate(mTileWidth * gridX, mTileHeight * gridY);
gl::scale(Vec2f(1.0f, mTileHeight / mTileWidth));
int toggle = mRand.nextInt(4);
if (toggle == 0) gl::rotate(-90.0f);
if (toggle == 1) gl::rotate(0.0f);
if (toggle == 2) gl::rotate(90.0f);
if (toggle == 3) gl::rotate(180.0f);
for (int i = 0; i < mCircleCount; i++) {
float diameter = lmap(float(i), 0.0f, mCircleCount - 1.0f, mTileWidth, mEndSize);
float offset = lmap(float(i), 0.0f, mCircleCount - 1.0f, 0.0f, mEndOffset);
gl::drawStrokedCircle(Vec2f(offset, 0.0f), diameter / 2.0f);
}
gl::popMatrices();
}
}
gl::popMatrices();
}
示例7: getSheepDir
int getSheepDir (int sheepPos, int *theGrid, int gridX, Rand thisRand) {
// smart sheep will move toward something to eat if it is adjacent.
// eventually, we might re-introduce tree age; sheep can only eat young trees and
// must move around old trees.
// do fires kill sheep?
//
int foodDirections[4] = {0,0,0,0};
int nFoodDirs=0, sheepDir=0;
//
if (*(theGrid+1)==1) {
foodDirections[nFoodDirs]=1;
nFoodDirs++;
};
if (*(theGrid-1)==1) {
foodDirections[nFoodDirs]=-1;
nFoodDirs++;
};
if (*(theGrid+gridX)==1) {
foodDirections[nFoodDirs] = gridX;
nFoodDirs++;
};
if (*(theGrid-gridX)==1) {
foodDirections[nFoodDirs] = -gridX;
nFoodDirs++;
};
//
if (nFoodDirs>0) {
// there is something we can eat...
sheepDir = foodDirections[thisRand.nextInt(nFoodDirs)];
}
else {
sheepDir = getRandDir(gridX, thisRand);
};
//
return sheepDir;
};