本文整理汇总了C++中RNG函数的典型用法代码示例。如果您正苦于以下问题:C++ RNG函数的具体用法?C++ RNG怎么用?C++ RNG使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RNG函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: shMonster
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;
}
示例2: RNG
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;
}
}
}
}
示例3: test_s
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");
}
示例4: buildTwistyCorridor
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);
}
}
示例5: RNG
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;
}
示例6: nebu_prep
/**
* @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();
}
示例7: test_a_long_double
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 */
}
示例8: shFeature
/* 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;
}
示例9: pickCompilerTarget
/* 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;
}
示例10: isExplosive
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;
}
}
}
示例11: test_a_double
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 */
}
示例12: test_e_long_double
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);
}
示例13: pickAMonsterIlk
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 ()));
}
示例14: streaming_up_down_test
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);
}
示例15: randomWorld
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)];
}