• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ RNG函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中RNG函数的典型用法代码示例。如果您正苦于以下问题:C++ RNG函数的具体用法?C++ RNG怎么用?C++ RNG使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了RNG函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:ronw23,项目名称:prime-osx,代码行数:35,代码来源:Room.cpp


示例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;
            }
        }
    }
}
开发者ID:orbisvicis,项目名称:prime,代码行数:29,代码来源:TwistyRooms.cpp


示例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");
}
开发者ID:T-J-Teru,项目名称:gcc,代码行数:34,代码来源:builtin-sprintf.c


示例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);
    }

}
开发者ID:orbisvicis,项目名称:prime,代码行数:33,代码来源:TwistyRooms.cpp


示例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;
}
开发者ID:ronw23,项目名称:prime-osx,代码行数:26,代码来源:Room.cpp


示例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();
}
开发者ID:Kinniken,项目名称:NoxImperii,代码行数:32,代码来源:nebula.c


示例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 */
}
开发者ID:vinriviere,项目名称:m68k-atari-mint-gcc,代码行数:9,代码来源:builtin-sprintf.c


示例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;
}
开发者ID:ronw23,项目名称:prime-osx,代码行数:11,代码来源:Vat.cpp


示例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;
}
开发者ID:ronw23,项目名称:prime-osx,代码行数:53,代码来源:MatterCompiler.cpp


示例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;
        }
    }
}
开发者ID:ronw23,项目名称:prime-osx,代码行数:51,代码来源:Droid.cpp


示例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 */
}
开发者ID:T-J-Teru,项目名称:gcc,代码行数:14,代码来源:builtin-sprintf.c


示例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);
}
开发者ID:T-J-Teru,项目名称:gcc,代码行数:34,代码来源:builtin-sprintf.c


示例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 ()));
}
开发者ID:ronw23,项目名称:prime-osx,代码行数:30,代码来源:Monster.cpp


示例14: streaming_up_down_test

static void streaming_up_down_test(const SRCParams &params)
{
  // 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);
}
开发者ID:9060,项目名称:ac3filter.valib,代码行数:26,代码来源:test_src.cpp


示例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)];
}
开发者ID:orbisvicis,项目名称:prime,代码行数:16,代码来源:LoreHelp.cpp


示例16: menu_small_exit

/**
 * @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();
}
开发者ID:zid,项目名称:naev,代码行数:33,代码来源:menu.c


示例17: RNG

PatchMatch::PatchMatch (int patch_height, int patch_width) {
    
    PATCHHEIGHT = patch_height, PATCHWIDTH = patch_width;
    
    genRandom = RNG(time(NULL));
    
}
开发者ID:Rosaniline,项目名称:repetitionExtract,代码行数:7,代码来源:PatchMatch.cpp


示例18: xDistribution

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;
}
开发者ID:WingBot,项目名称:pedsim_ros,代码行数:16,代码来源:shoppingplanner.cpp


示例19: main

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;
}
开发者ID:SahinEgilmez,项目名称:C_Works,代码行数:26,代码来源:HW3_Sahin_Egilmez_131044059_part1.c


示例20: commodity_Jettison

/**
 * @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 );
   }
}
开发者ID:Arakash,项目名称:naev,代码行数:35,代码来源:economy.c



注:本文中的RNG函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ RNG_RandomUpdate函数代码示例发布时间:2022-05-30
下一篇:
C++ RND_RAND函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap