这篇教程C++ srand函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中srand函数的典型用法代码示例。如果您正苦于以下问题:C++ srand函数的具体用法?C++ srand怎么用?C++ srand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了srand函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: mallocvoid LevelGrid::InitializeLevel(void){ // Give the level vertices some space this->m_LeftLevelVertices = (hgeVector**) malloc(sizeof(hgeVector*) * this->m_NumY); this->m_RightLevelVertices = (hgeVector**) malloc(sizeof(hgeVector*) * this->m_NumY); // Create some storage for track indices this->m_LeftLevelIndices = (unsigned int*) malloc(sizeof(unsigned int) * this->m_NumY); this->m_RightLevelIndices = (unsigned int*) malloc(sizeof(unsigned int) * this->m_NumY); // Retrieve the list of players to generate activators std::list<Player*> *p = this->m_PlayerManager->GetPlayers(); // Constructed the grid vertices, now build the level for (int i = 0 ; i < this->m_NumY ; ++i) { // Construct the left and right vertexlist this->m_LeftLevelVertices[i] = this->m_GridVertices[i][StartX]; this->m_RightLevelVertices[i] = this->m_GridVertices[i][StartX + this->m_TrackWidth]; // Store indices this->m_LeftLevelIndices[i] = StartX; this->m_RightLevelIndices[i] = StartX + this->m_TrackWidth; // Only create a "turn" every 2 vertices vertical if (i % 2 == 0) { int lr = rand() % 3 - 1; if (StartX + lr < (this->m_NumX - this->m_TrackWidth) && StartX + lr > 0) { StartX += lr; } } } // Create a vector from the list, we need direct lookup std::vector<Player*> players(p->begin(), p->end()); // Initialize the number of activators this->m_NumActivators = 0; // Only add activators whenever there are players if (players.size() > 0) { // Determine the vertical distribution for activators int verticalDistribution = this->m_NumY / (players.size() * NUM_ACTIVATORS); // Create the activator array this->m_Activators = (Activator**) malloc(sizeof(Activator*) * (this->m_NumActivators = NUM_ACTIVATORS * players.size())); // This feels a bit hackish... std::vector<std::vector<unsigned int>> activatorTypes; for (int i = 0 ; i < players.size() ; ++i) { std::vector<unsigned int> activators; for (int j = 0 ; j < NUM_ACTIVATORS ; ++j) { activators.push_back(j); } std::random_shuffle(activators.begin(), activators.end()); activatorTypes.push_back(activators); } std::random_shuffle(activatorTypes.begin(), activatorTypes.end()); // Retrieve viewport unsigned int width = this->m_Engine->GetWidth(); unsigned int height = this->m_Engine->GetHeight(); // Determine deltas float dx = width / this->m_NumX; float dy = height / this->m_NumY; // Define the activator length list ACTIVATOR_LENGTH_LIST; // Run through the players and then run though activators to make sure that // we're never generating two activators for one player in sequence int y = 0; int n = 0; std::vector<std::vector<unsigned int>>::const_iterator it; for (int i = 0 ; i < NUM_ACTIVATORS ; ++i) { int k = 0; for (it = activatorTypes.begin() ; it != activatorTypes.end() ; ++it) { // Fetch a random int between left and right on track y int x = (rand() % ((this->m_RightLevelIndices[y] - 2) - (this->m_LeftLevelIndices[y] + 2))) + (this->m_LeftLevelIndices[y] + 2); // Fetch the activator type pointed to by i unsigned int activatorType = (*it).at(i); // Offset y in some direction srand(x * y); int offsetY = rand() % 5; if (y + offsetY >= this->m_NumY) { y -= offsetY; }//.........这里部分代码省略.........
开发者ID:ofx,项目名称:dr,代码行数:101,
示例2: mainint main(int argc, char **argv){ char *iFuncName; int m, info; int maxEvals; int iFuncNumb, n, numIter; int contSucess = 0; int type; real *x; real epsg, epsf, epsx; real maxiters = 0; long fnEvals, mediaFnEvals = 0; long gradEvals, mediaGradEvals = 0; bool sucess; int64_t initialTime, finalTime; int64_t deltaTime, mediaTime = 0; ap::real_1d_array xBFGS; MGrasp *mgrasp; LBFGS *lbfgs; Funcao *func; real *gaps; real mediaGaps[7]; if (argc < 7) { usage(); return 1; } epsg = 0.000001; epsf = 0.000001; epsx = 0.000001; maxiters = 0; iFuncName = argv[1]; iFuncNumb = getFuncNumb(iFuncName); n = atoi(argv[2]); maxEvals = atoi(argv[3]); numIter = atoi(argv[4]); type = getType(argv[5]); m = atoi(argv[6]); if (iFuncNumb == -1) { printf("Fun C++ srand48函数代码示例 C++ sr_spew函数代码示例
|