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); } }
void TestCanvas::testCubicBezier(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(-50.f, 50.f); float y2 = y1 + randFloat(-50.f, 50.f); float x3 = x2 + randFloat(-50.f, 50.f); float y3 = y2 + randFloat(-50.f, 50.f); float x4 = x3 + randFloat(-50.f, 50.f); float y4 = y3 + randFloat(-50.f, 50.f); canvas->moveTo(x1, y1); for (int j = randInt(1, 10); j > 0; j--) { canvas->bezierTo(x2, y2, x3, y3, x4, y4); x1 = x2; y1 = y2; // P2 x2 = 2 * x4 - x3; // Q2=2P4-P3 y2 = 2 * y4 - y3; x3 = 4 * (x4 - x3) + x1; // Q3=4(P4-P3)+P2 y3 = 4 * (y4 - y3) + y1; x4 = x3 + randFloat(-50.f, 50.f); y4 = y3 + randFloat(-50.f, 50.f); } if (s_randStyle) { canvas->setPen(0xFF000000 | randInt(0, 0xFFFFFF), -1.f, -1, 0); } canvas->drawPath(true, false); } }
/*! \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; }
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); } }
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"); }
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)); } }
/*! 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(); } }
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); } } } }
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."); }
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); } }
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 }
// 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; } }
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(); }
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; }
/** 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; }
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); }
void CadMdiChild::on_actionAdd_Random_Lines_triggered() { QTime myTimer; myTimer.start(); 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 x2 = x1 + randInt(-50, 50); double y2 = y1 + randInt(-50, 50); builder->append(std::make_shared<lc::Line>(lc::geo::Coordinate(x1, y1), lc::geo::Coordinate(x2, y2), layer)); } qDebug() << "Create : " << myTimer.elapsed(); myTimer.start(); builder->execute(); qDebug() << "Process : " << myTimer.elapsed(); /* // This retreival is currently expensive because it makes a copy. // The idea is to not make a copy by returning it 'const'. To decides yet lc::EntityContainer container=document()->entityContainer(); myTimer.restart(); qDebug() << "Entities Total " << container.allEntities().size(); qDebug() << "Selection Time : " << myTimer.elapsed() << "ms\n"; myTimer.restart(); lc::EntityContainer itemsInArea = container.entitiesByArea(lc::geo::Area(lc::geo::Coordinate(200,200), lc::geo::Coordinate(350,350))); qDebug() << "Entities in area : " << itemsInArea.allEntities().size(); qDebug() << "Selection Time : " << myTimer.elapsed() << "ms\n"; myTimer.restart(); lc::EntityContainer itemsOnLayerWithinArea = itemsInArea.entitiesByLayer(storageManager()->layerByName("1")); qDebug() << "Entities on layer within above selection : " << itemsOnLayerWithinArea.allEntities().size(); qDebug() << "Selection Time : " << myTimer.elapsed() << "ms\n"; myTimer.restart(); lc::EntityContainer itemsOnDocument = container.entitiesByLayer(storageManager()->layerByName("1")); qDebug() << "Entities on this layer within document : " << itemsOnDocument.allEntities().size(); qDebug() << "Selection Time : " << myTimer.elapsed() << "ms\n"; */ }
float randFloat(float min,float max) { if (min==max) return min; return ( (float)(randInt( (int)min, (int)max)) + ((float)rand() / ((float)RAND_MAX + 1))); }
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; }
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; }
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(); } } }
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; } }
AGWorm::AGWorm(){ creatureAuthor = "Andreas Gysin"; creatureName = "El Worm"; creatureVersion = "Alpha"; // setDate(2011, 6, 10); //Y,M,D frameCount = 0; num = randInt(7, 22); // (7, 22) len = randFloat(2, 15); damp = randFloat(0.85, 0.95); k = randFloat(0.15, 0.3); radius = randFloat(1.5, 2.5); rSpeed = randFloat(50.f, 150.f); rDamp = randFloat(0.005, 0.02); nervosismo = randFloat(0.01, 0.3); freq1 = randFloat(0.05, 0.2); freq2 = randFloat(0.08, 1.1); nodes = *new vector<Node>(); springs = *new vector<Spring>(); for (int i = 0; i<num; i++){ Vec3f p = pos + Vec3f(randFloat(-1, 1), randFloat(-1, 1), randFloat(-1, 1)); Node n = *new Node(p, damp); nodes.push_back(n); } for(int i = 0; i<num-1; i++){ Spring s = *new Spring(nodes.at(i), nodes.at(i+1), len, k ); springs.push_back(s); } dest = *new Vec3f(); }
Vector MeshGroup::getRandomPointFacing( const Vector& dir ) { // an acceptable mesh has 2 coordinates: a mesh# and a triangle # on the mesh vector< pair<int,int> > acceptableTris_meshNo_triNo ; for( int i = 0 ; i < meshes.size() ; i++ ) { Mesh *mesh = meshes[ i ] ; for( int j = 0 ; j < mesh->tris.size() ; j++ ) { Triangle& tri = mesh->tris[j]; if( tri.normal • dir < 0 ) { // this face is acceptable acceptableTris_meshNo_triNo.push_back( make_pair( i, j ) ) ; } } } // choose a face at random int face = randInt( 0, acceptableTris_meshNo_triNo.size() ) ; pair<int,int> facepair = acceptableTris_meshNo_triNo[ face ] ; Triangle& tri = meshes[ facepair.first ]->tris[ facepair.second ] ; // get a random point on the triangle return tri.getRandomPointOn() ; }
int T() { if (randInt(10) < 7) { printf("%c", randChar("0123456789")); } else { printf("("); E(); printf(")"); } }
int E() { if (randInt(10) < 5) { T(); printf("%c", randChar("+-*/")); E(); } else { T(); } }
int* CellsRegistry::reserveRandomAvailableGroundPosAround(int* returnPos, int parentX, int parentY, int sqrLen){ int xMin = max(0, parentX-sqrLen); int xMax = min(world.length-1, parentX+sqrLen); int yMin = max(0, parentY-sqrLen); int yMax = min(world.length-1, parentY+sqrLen); int nbAvailablePos = 0; for (int i=xMin; i<=xMax; ++i){ for (int j=yMin; j<=yMax; ++j){ if (registryXYZ[i][j][0] == NULL){ availablePosTmp[nbAvailablePos][0] = i; availablePosTmp[nbAvailablePos][1] = j; ++nbAvailablePos; } } } if (nbAvailablePos == 0) return NULL; int i = randInt(nbAvailablePos); returnPos[0] = availablePosTmp[i][0]; returnPos[1] = availablePosTmp[i][1]; return returnPos; }
void Pony48Engine::placenew() { ostringstream oss; oss << "res/tiles/" << randInt(1,2) * 2 << ".xml"; if(movePossible()) //Make sure there aren't no blank spaces or something { while(true) //Could possibly hang here for a while { int x = randInt(0, BOARD_WIDTH-1); int y = randInt(0, BOARD_HEIGHT-1); if(m_Board[x][y] != NULL) continue; m_Board[x][y] = loadTile(oss.str()); break; } } }
void Substrate::initializeCanvas() { m_image.fill(255, 255, 255); m_cracks.clear(); // make random crack seeds m_gridData.clear(); m_gridData.resize(m_image.width()*m_image.height(), GridData(UNCRACKED, UNCRACKED, NO_SHAPE)); for(uint k = 0; k < m_numInitialCracks; k++) { int c = m_image.width()/2; //randInt(0, m_image.width()); int r = m_image.height()/2; //randInt(0, m_image.height()); m_crackedPixels.push_back(r*m_image.width() + c); m_gridData[r*m_image.width() + c].angle = randInt(0, 360); m_gridData[r*m_image.width() + c].objectId = uniqueId(); } // make initial cracks m_curvedPercentage = 1.0f; for(uint k = 0; k < m_numInitialCracks; ++k) makeCrack(); // no more circles m_curvedPercentage = 0.0f; }
/* Interrupt routine to run when the timer expires */ void interrupt isr_timer1(void) { /* Fill the screen with a random color */ memset_fast(lcd_Ram, randInt(0,255), LCD_SIZE); /* Must acknowledge that the interrupt occured to clear the flag */ int_Acknowledge = INT_TIMER1; }