//RETURNS: 0 on success, -1 o/w int shMapLevel::pushCreature (shCreature *c, shDirection dir) { shDirection dirlist[3]; int r = RNG (1, 2); int i; dirlist[0] = dir; dirlist[r] = (shDirection) ((dir + 1) % 8); dirlist[3-r] = (shDirection) ((dir + 7) % 8); for (i = 0; i < 3; i++) { int x = c->mX; int y = c->mY; shDirection dir = dirlist[i]; moveForward (dir, &x, &y); if (isObstacle (x, y) or isOccupied (x, y)) continue; return moveCreature (c, x, y); } if (c->isHero ()) { I->p ("You are crushed between the walls!"); } else if (Hero.canSee (c)) { I->p ("%s is crushed!", THE (c)); } c->die (kMisc, "Crushed by a garbage compactor"); return -1; }
int shMapLevel::makeHospital (int sx, int sy, int ex, int ey) { int dx; int dy; shMonster *docbot; int roomid = mSquares[sx][sy].mRoomId; dx = (sx + ex + RNG (0, 1)) / 2; dy = (sy + ey + RNG (0, 1)) / 2; docbot = new shMonster (kMonDocbot); putCreature (docbot, dx, dy); docbot->mDoctor.mHomeX = dx; docbot->mDoctor.mHomeY = dy; docbot->mDoctor.mRoomID = roomid; for (int i = 0; i < kMedMaxService; ++i) docbot->mDoctor.mPermute[i] = i; shuffle (docbot->mDoctor.mPermute, kMedMaxService, sizeof (int)); mRooms[roomid].mType = shRoom::kHospital; debug.log ("made hospital on level %d", mDLevel); return 1; }
void shMapLevel::buildSnuggledRooms () { int x; int y; int ey; for (y = 0; y < mRows; y++) { for (x = 0 ; x < mColumns; x++) { if (RNG (4)) { x += RNG (2); } ey = fiveByFiveClearance (x, y); if (ey) { if (ey > y + 9) { ey = y + 5; } else if (ey > y + 5) { ey = RNG (y + 5, ey); } // draw (); // I->getChar (); buildRoomOrElRoom (x, y, ey); x += 5; } } } }
test_s (int i) { EQL ( 0, 1, "%s", ""); EQL ( 0, 1, "%s", "\0"); EQL ( 1, 2, "%1s", ""); EQL ( 1, 2, "%s", "1"); EQL ( 2, 3, "%2s", ""); EQL ( 2, 3, "%s", "12"); EQL ( 2, 3, "%s%s", "12", ""); EQL ( 2, 3, "%s%s", "", "12"); EQL ( 2, 3, "%s%s", "1", "2"); EQL ( 3, 4, "%3s", ""); EQL ( 3, 4, "%3s", "1"); EQL ( 3, 4, "%3s", "12"); EQL ( 3, 4, "%3s", "123"); EQL ( 3, 4, "%3.3s", "1"); EQL ( 3, 4, "%3.3s", "12"); EQL ( 3, 4, "%3.3s", "123"); EQL ( 3, 4, "%3.3s", "1234"); EQL ( 3, 4, "%3.3s", "12345"); EQL ( 3, 4, "%s %s", "1", "2"); EQL ( 4, 5, "%s %s", "12", "3"); EQL ( 5, 6, "%s %s", "12", "34"); EQL ( 5, 6, "[%s %s]", "1", "2"); EQL ( 6, 7, "[%s %s]", "12", "3"); EQL ( 7, 8, "[%s %s]", "12", "34"); /* Verify the result of a conditional expression involving string literals is in the expected range of their lengths. */ RNG ( 0, 3, 4, "%-s", i ? "" : "123"); RNG ( 1, 4, 5, "%-s", i ? "1" : "1234"); RNG ( 2, 5, 6, "%-s", i ? "12" : "12345"); RNG ( 3, 6, 7, "%-s", i ? "123" : "123456"); }
void shMapLevel::buildTwistyRooms () { int i = 1000; int n = 0; int x, y; n = buildTwistyCorridor (RNG (mColumns / 3, 2 * mColumns / 3), 4, kSouth); while (--i and n < 4 * (mRows + mColumns)) { do { x = RNG (mColumns); y = RNG (mRows); } while (!TESTSQ (x, y, kFloor)); n += buildTwistyCorridor (x, y, (shDirection) (2 * RNG (4))); if (n > 4 * (mRows + mColumns)) break; } buildSnuggledRooms (); // wallCorridors (); n = RNG (1, 6) + RNG (1, 6) + RNG (1, 6) + RNG (1, 6); for (i = 0; i < n; i++) { do { x = RNG (mColumns); y = RNG (mRows); } while (!TESTSQ (x, y, kFloor) or isObstacle (x, y)); putObject (generateObject (), x, y); } }
int shMapLevel::makeNest (int sx, int sy, int ex, int ey) { int x, y; int roomid = mSquares[sx][sy].mRoomId; if (mDLevel > 12) { shMonster *queen = new shMonster (kMonAlienQueen); queen->mStrategy = shMonster::kLurk; putCreature (queen, RNG (sx + 1, ex - 1), RNG (sy + 1, ey -1)); } debug.log ("made nest on level %d", mDLevel); for (x = sx + 1; x < ex ; x++) { for (y = sy + 1; y < ey; y++) { if (!isOccupied (x, y)) { shMonster *alien = NULL; if (x%4 and y%3) { alien = new shMonster (kMonAlienEgg); } else if (!RNG (8) and mDLevel >= 8) { alien = new shMonster (kMonAlienWarrior); alien->mStrategy = shMonster::kLurk; } if (alien) { putCreature (alien, x, y); } } /* No stairs in a nest! */ //mSquares[x][y].mFlags &= ~shSquare::kStairsOK; } } mRooms[roomid].mType = shRoom::kNest; return 1; }
/** * @brief Prepares the nebualae to be rendered. * * @param density Density of the nebula (0-1000). * @param volatility Volatility of the nebula (0-1000). */ void nebu_prep( double density, double volatility ) { (void)volatility; int i; nebu_view = 1000. - density; /* At density 1000 you're blind */ nebu_dt = 2000. / (density + 100.); /* Faster at higher density */ nebu_timer = nebu_dt; nebu_npuffs = density/4.; nebu_puffs = realloc(nebu_puffs, sizeof(NebulaPuff)*nebu_npuffs); for (i=0; i<nebu_npuffs; i++) { /* Position */ nebu_puffs[i].x = (double)RNG(-NEBULA_PUFF_BUFFER, SCREEN_W + NEBULA_PUFF_BUFFER); nebu_puffs[i].y = (double)RNG(-NEBULA_PUFF_BUFFER, SCREEN_H + NEBULA_PUFF_BUFFER); /* Maybe make size related? */ nebu_puffs[i].tex = RNG(0,NEBULA_PUFFS-1); nebu_puffs[i].height = RNGF() + 0.2; } /* Generate the overlay. */ nebu_genOverlay(); }
test_a_long_double (void) { EQL ( 6, 7, "%.0La", 0.0L); /* 0x0p+0 */ EQL ( 6, 7, "%.0La", 1.0L); /* 0x8p-3 */ EQL ( 6, 7, "%.0La", 2.0L); /* 0x8p-2 */ RNG ( 8, 13, 14, "%.1La", 3.0L); /* 0xc.0p-2 */ RNG ( 9, 14, 15, "%.2La", 4.0L); /* 0xa.00p-1 */ }
/* Produces random vats for matter compiler. */ shFeature * shFeature::newVat () { shFeature *vat = new shFeature (); vat->mType = shFeature::kVat; vat->mVat.mHealthy = RNG (-2, 2); vat->mVat.mRadioactive = RNG (10) > 0; vat->mVat.mAnalyzed = RNG (2); return vat; }
/* Returns ilk name and kNoFeature in kind or NULL and feature type in kind. */ static const char * pickCompilerTarget (int score, shFeature::Type *kind) { shMenu *pickIlk = I->newMenu ("choose object type", 0); shFeature *f = Level->getFeature (Hero.mX, Hero.mY); char letter = 'a'; const char *headerstr = NULL; int header_placed = 1; int options = 0; for (int i = 0; i < pickCount; ++i) { int skill_or_luck = (score >= pickData[i].score or // Through skill. !RNG (pickData[i].score)); // Through luck. if (pickData[i].score == 0) { /* Do not place header unless an object needs it. */ headerstr = pickData[i].dispName; header_placed = 0; /* Give first (random) pick and others 80% of the time if other conditions are fulfilled. */ } else if ((RNG (5) or !options) and skill_or_luck) { /* Offer features only if place is available. */ if ((pickData[i].type != NOFEATURE and f == NULL and /* Offered feature is not a door or... */ (pickData[i].type != shFeature::kDoorOpen or /* ...it matches both door requirements. */ (isDoorLevel () and isDoorSpot ()))) /* Objects always fine. */ or (pickData[i].type == NOFEATURE)) { if (!header_placed) { pickIlk->addHeader (headerstr); header_placed = 1; } pickIlk->addPtrItem (letter++, pickData[i].dispName, &pickData[i]); if (letter > 'z') letter = 'A'; ++options; } } } /* Time to choose. */ shIlkPickData *ilkdata = NULL; if (options > 1) { /* Have options besides completely random. */ pickIlk->getPtrResult ((const void **) &ilkdata, NULL); } delete pickIlk; /* Hero gets or wants random item? */ if (options == 1 or !ilkdata or ilkdata->ilkName == pickData[1].ilkName) { *kind = NOFEATURE; return NULL; } /* Return chosen feature or object. */ *kind = ilkdata->type; return ilkdata->ilkName; }
void shMonster::findPetGoal () { int x, y, n, dist; shCreature *c; shObject *obj; int bestdist = 99; for (n = 5; n > 0; n--) { for (x = mX - n; x <= mX + n; x++) { for (y = mY - n; y <= mY + n; y++) { if (!mLevel->isInBounds (x, y)) { continue; } c = mLevel->getCreature (x, y); if (c and !c->isHero () and !c->isPet () and c->isHostile () and /* canSee (c) and */ (c->mCLevel <= mCLevel + 1 or isExplosive ())) { dist = distance (mX, mY, x, y); if (dist < bestdist) { bestdist = dist; mDestX = x; mDestY = y; } } obj = mLevel->findObject (x, y, kObjBeer); if (obj) { dist = distance (mX, mY, x, y); if (dist < bestdist) { bestdist = dist; mDestX = x; mDestY = y; } } } } } if (99 == bestdist and !RNG(6)) { /* nothing interesting, let's wander */ if (RNG (3)) { mDestX = Hero.mX + RNG (13) - 6; mDestY = Hero.mY + RNG (9) - 4; mLevel->findNearbyUnoccupiedSquare (&mDestX, &mDestY); } else { mDestX = Hero.mX; mDestY = Hero.mY; } } }
test_a_double (double d) { EQL ( 6, 7, "%.0a", 0.0); /* 0x0p+0 */ EQL ( 6, 7, "%.0a", 1.0); /* 0x8p-3 */ EQL ( 6, 7, "%.0a", 2.0); /* 0x8p-2 */ EQL ( 8, 9, "%.1a", 3.0); /* 0xc.0p-2 */ EQL ( 9, 10, "%.2a", 4.0); /* 0x8.00p-1 */ EQL (10, 11, "%.3a", 5.0); /* 0xa.000p-1 */ /* d is in [ 0, -DBL_MAX ] */ RNG ( 6, 10, 11, "%.0a", d); /* 0x0p+0 ... -0x2p+1023 */ RNG ( 6, 12, 13, "%.1a", d); /* 0x0p+0 ... -0x2.0p+1023 */ RNG ( 6, 13, 14, "%.2a", d); /* 0x0p+0 ... -0x2.00p+1023 */ }
test_e_long_double (void) { EQL (12, 13, "%Le", 1.0e0L); EQL (13, 14, "%Le", -1.0e0L); EQL (12, 13, "%Le", 1.0e+1L); EQL (13, 14, "%Le", -1.0e+1L); EQL (12, 13, "%Le", 1.0e+12L); EQL (13, 14, "%Le", -1.0e+12L); EQL (13, 14, "%Le", 1.0e+123L); EQL (14, 15, "%Le", -1.0e+123L); EQL (12, 13, "%Le", 9.999e+99L); EQL (12, 13, "%Le", 9.9999e+99L); EQL (12, 13, "%Le", 9.99999e+99L); #if __DBL_DIG__ < __LDBL_DIG__ EQL (12, 13, "%Le", 9.999999e+99L); #else RNG (12, 13, 14, "%Le", 9.999999e+99L); #endif /* The actual output of the following directive depends on the rounding mode. */ /* EQL (12, "%Le", 9.9999994e+99L); */ EQL (12, 13, "%Le", 1.0e-1L); EQL (12, 13, "%Le", 1.0e-12L); EQL (13, 14, "%Le", 1.0e-123L); EQL ( 6, 7, "%.0Le", 1.0e-111L); EQL ( 8, 9, "%.1Le", 1.0e-111L); EQL (19, 20, "%.12Le", 1.0e-112L); EQL (20, 21, "%.13Le", 1.0e-113L); }
shMonId pickAMonsterIlk (int level) { int baselevel = level; int n = 0; shVector <shMonId> v; shMonId ilk; int i; int c; // rarity = RNG (3) ? 1 : RNG (3) ? 2 : 3; while (0 == (n = MonsterIlksGroupedByLevel[baselevel].count ())) { baselevel--; } for (i = 0; i < n; i++) { ilk = MonsterIlksGroupedByLevel[baselevel].get (i); c = MonIlks[ilk].mProbability; while (c--) { v.add (ilk); } } if (!v.count ()) { return shMonId (0); } return v.get (RNG (v.count ())); }
static void streaming_up_down_test(const SRCParams ¶ms) { // Source noise Samples noise(noise_size); RNG(seed).fill_samples(noise, noise_size); // Upsampled buffer Samples buf1(size_t(double(noise_size + 1) * params.fd / params.fs) + 1); // Downsampled buffer Samples buf2(noise_size + 100); StreamingSRC src; BOOST_REQUIRE(src.open(params)); size_t buf1_data = resample(src, noise, noise_size, buf1, buf1.size()); BOOST_REQUIRE(src.open(SRCParams(params.fd, params.fs, params.a, params.q))); size_t buf2_data = resample(src, buf1, buf1_data, buf2, buf2.size()); BOOST_CHECK(abs(int(buf2_data) - int(noise_size)) <= 1); // Resample introduces not more than -A dB of noise. // 2 resamples introduces twice more noise, -A + 6dB sample_t diff = diff_resampled(params, noise, buf2, MIN(noise_size, buf2_data)); BOOST_MESSAGE("Transform: " << params.fs << "Hz <-> " << params.fd << "Hz Diff: " << value2db(diff) << " dB"); BOOST_CHECK_LE(value2db(diff), -params.a + 7); }
const char * randomWorld () { static const char *planets[] = { "B-612","Trantos","Coruscant","Tatooine","Delta Pavonis", "Aurora","the Ringworld","Phobos","Fribbulus Xax","Arrakis", "Limbic System","Gnosticus IV","Asturiax","Giedi Prime", "Caladan","Deimos","IX","Sigma Draconis VII","Salusa Secunda", "Richese","Aiur","Tarsonis","Mar Sara","Chau Sara","Bhekar Ro", "Umoja","Char","Zerus" }; const int numplanets = sizeof (planets) / sizeof (char *); if (RNG (3)) return randomPlanet (); else return planets[RNG (numplanets)]; }
/** * @brief Closes the small ingame menu and goes back to the main menu. * @param str Unused. */ static void menu_small_exit( unsigned int wid, char* str ) { (void) str; unsigned int info_wid; /* if landed we must save anyways */ if (landed) { /* increment time to match takeoff */ ntime_inc( RNG( 2*NTIME_UNIT_LENGTH, 3*NTIME_UNIT_LENGTH ) ); save_all(); land_cleanup(); } /* Close info menu if open. */ if (menu_isOpen(MENU_INFO)) { info_wid = window_get("Info"); window_destroy( info_wid ); menu_Close(MENU_INFO); } /* Stop player sounds because sometimes they hang. */ player_abortAutonav( "Exited game." ); player_stopSound(); /* Clean up. */ window_destroy( wid ); menu_Close(MENU_SMALL); menu_main(); }
PatchMatch::PatchMatch (int patch_height, int patch_width) { PATCHHEIGHT = patch_height, PATCHWIDTH = patch_width; genRandom = RNG(time(NULL)); }
Ped::Tvector ShoppingPlanner::getRandomAttractionPosition() const { Ped::Tvector randomPosition = attraction->getPosition(); // → add random part QSizeF size = attraction->getSize(); std::uniform_real_distribution<double> xDistribution ( -size.width() /2, size.width() /2 ); std::uniform_real_distribution<double> yDistribution ( -size.height() /2, size.height() /2 ); double xdiff = xDistribution ( RNG() ); double ydiff = yDistribution ( RNG() ); randomPosition += Ped::Tvector ( xdiff, ydiff ); return randomPosition; }
int main() { int number, guess, difference, option;/*defines integers*/ char play_exit;/*defines players choose*/ /*print to screen questions for play or exit?*/ printf(" “P” or “p” for play and “E” or “e” to exit\n"); option=Play(play_exit);/*players choice*/ /*this loop for play game if players choice is 'p',*/ while(option==1) { number=RNG();/*create the random number*/ /*this loop for continue if players choice is wrong.*/ while(number!=guess) { printf("Please guess between 1 and 10 ");/*wants guess*/ scanf("%d", &guess);/*take the guess*/ /*calculate the difference*/ difference=CalculateTheDifference(guess,number); /*print to screen the feedback*/ WarnThePlayer(difference,number); } /*print to screen questions for playing again?*/ printf(" Do you want to play again?(“P” or “p” for play and “E” or “e” to exit)\n"); scanf("%c", &play_exit);/*take the players choice*/ option=Play(play_exit);/*define the choice*/ } return 0; }
/** * @brief Throws cargo out in space graphically. * * @param pilot ID of the pilot throwing the stuff out * @param com Commodity to throw out. * @param quantity Quantity thrown out. */ void commodity_Jettison( int pilot, Commodity* com, int quantity ) { (void)com; int i; Pilot* p; int n, effect; double px,py, bvx, bvy, r,a, vx,vy; p = pilot_get( pilot ); n = MAX( 1, RNG(quantity/10, quantity/5) ); px = p->solid->pos.x; py = p->solid->pos.y; bvx = p->solid->vel.x; bvy = p->solid->vel.y; for (i=0; i<n; i++) { effect = spfx_get("cargo"); /* Radial distribution gives much nicer results */ r = RNGF()*25 - 12.5; a = 2. * M_PI * RNGF(); vx = bvx + r*cos(a); vy = bvy + r*sin(a); /* Add the cargo effect */ spfx_add( effect, px, py, vx, vy, SPFX_LAYER_BACK ); } }
void initializeMonsters () { for (int i = 0; i < kMonNumberOf; ++i) { shMonsterIlk *ilk = &MonIlks[i]; ilk->mId = shMonId (i); if (ilk->mGlyph.mTileY == -1) ilk->mGlyph.mTileY = sym2TileY (ilk->mGlyph.mSym); if (ilk->mGlyph.mTileX == 0) { /* White ASCII character. */ /* NotEye will repaint the glyph to right color. 24 is simply far enough to right to be safely assumed free. */ ilk->mGlyph.mTileX = 24 + ilk->mGlyph.mColor; } for (int j = 0; j < MAXPOWERS; ++j) { ilk->mPowers[j] and ++ilk->mNumPowers; } for (int j = 0; j < MAXATTACKS; ++j) { ilk->mAttackSum += ilk->mAttacks[j].mProb; } // Temporarily, until monster generation mechanism is improved MonsterIlksGroupedByLevel[ilk->mBaseLevel].add (ilk->mId); } int roll = RNG (3); lizard[0] = roll == 0 ? kAttHeatRay : roll == 1 ? kAttFreezeRay : kAttPoisonRay; roll = RNG (6); lizard[1] = roll == 0 ? kAttHeatRay : roll == 1 ? kAttFreezeRay : roll == 2 ? kAttPoisonRay : roll == 3 ? kAttTransporterRay : roll == 4 ? kAttGammaRay : kAttStasisRay; roll = RNG (6); lizard[2] = roll == 0 ? kAttPoisonRay : roll == 1 ? kAttGammaRay : roll == 2 ? kAttTransporterRay : roll == 3 ? kAttGaussRay : roll == 4 ? kAttStasisRay : kAttDisintegrationRay; }
void clear() { min_val = max_val = min_val1 = max_val1 = 0.; rng = RNG((uint64)-1); weights.clear(); trained = false; max_buf_sz = 1 << 12; }
SolverParams::SolverParams() { struct X { uint32 strat[2]; uint32 self[3]; }; static_assert(sizeof(SolverParams) == sizeof(X), "Unsupported Padding"); std::memset((&seed)+1, 0, sizeof(uint32)*2); seed = RNG().seed(); heuOther = 3; heuMoms = 1; }
TrackerSamplerCSC::TrackerSamplerCSC( const TrackerSamplerCSC::Params ¶meters ) : params( parameters ) { className = "CSC"; mode = MODE_INIT_POS; rng = RNG( uint64( TIME( 0 ) ) ); }
Ped::Tvector ShoppingPlanner::createRandomOffset() const { const double radiusStd = 4; std::normal_distribution<double> radiusDistribution ( 0, radiusStd ); double radius = radiusDistribution ( RNG() ); std::discrete_distribution<int> angleDistribution {0,45,90,135,180,225,270,315,360}; double angle = angleDistribution ( RNG() ); Ped::Tvector randomOffset = Ped::Tvector::fromPolar ( Ped::Tangle::fromDegree ( angle ), radius ); // only update for significant shopping idea change if (randomOffset.lengthSquared() < 2.0) return Ped::Tvector(0, 0, 0); return randomOffset; }
GeneralizedPatchMatch::GeneralizedPatchMatch (int patch_height, int patch_width, int k) { PATCHHEIGHT = patch_height, PATCHWIDTH = patch_width, NEAREST_K = k; patchTool = patchTools(PATCHHEIGHT, PATCHWIDTH); genRandom = RNG(time(NULL)); }
void shMenu::getRandIntResult (int *value, int *count /* = NULL */) { shMenuChoice *choice = mChoices.get (RNG (mChoices.count ())); *value = choice->mValue.mInt; if (NULL != count) { *count = choice->mSelected; } }
//flood fills some muck starting at x,y int shMapLevel::floodMuck (int sx, int sy, shTerrainType type, int amount) { int x, y, i; shDirection dirs[4] = { kNorth, kSouth, kEast, kWest }; shDirection dir; int n = 0; shVector <int> points; points.add (xytop (sx, sy)); for (n = 0; n < amount;) { int p; if (0 == points.count ()) { return n; } p = points.removeByIndex (RNG (points.count ())); x = ptox (p); y = ptoy (p); if (!isFloor (x, y) or kSewage == getSquare (x, y) ->mTerr) { continue; } n++; if (RNG(2)) SETSQ (x, y, kSewage); for (i = 0; i < 4; i++) { dir = dirs[i]; int x2 = x; int y2 = y; if (moveForward (dir, &x2, &y2) and RNG (20) >= points.count ()) { points.add (xytop (x2, y2)); } } } return n; }
void shMenu::getRandPtrResult (const void **value, int *count /* = NULL */) { shMenuChoice *choice = mChoices.get (RNG (mChoices.count ())); *value = choice->mValue.mPtr; if (NULL != count) { *count = choice->mSelected; } }