本文整理汇总了C++中RandomInt函数的典型用法代码示例。如果您正苦于以下问题:C++ RandomInt函数的具体用法?C++ RandomInt怎么用?C++ RandomInt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RandomInt函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: CAddrInfo
CAddrInfo CAddrMan::Select_(bool newOnly)
{
if (size() == 0)
return CAddrInfo();
if (newOnly && nNew == 0)
return CAddrInfo();
// Use a 50% chance for choosing between tried and new table entries.
if (!newOnly &&
(nTried > 0 && (nNew == 0 || RandomInt(2) == 0))) {
// use a tried node
double fChanceFactor = 1.0;
while (1) {
int nKBucket = RandomInt(ADDRMAN_TRIED_BUCKET_COUNT);
int nKBucketPos = RandomInt(ADDRMAN_BUCKET_SIZE);
while (vvTried[nKBucket][nKBucketPos] == -1) {
nKBucket = (nKBucket + insecure_rand.randbits(ADDRMAN_TRIED_BUCKET_COUNT_LOG2)) % ADDRMAN_TRIED_BUCKET_COUNT;
nKBucketPos = (nKBucketPos + insecure_rand.randbits(ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
}
int nId = vvTried[nKBucket][nKBucketPos];
assert(mapInfo.count(nId) == 1);
CAddrInfo& info = mapInfo[nId];
if (RandomInt(1 << 30) < fChanceFactor * info.GetChance() * (1 << 30))
return info;
fChanceFactor *= 1.2;
}
} else {
// use a new node
double fChanceFactor = 1.0;
while (1) {
int nUBucket = RandomInt(ADDRMAN_NEW_BUCKET_COUNT);
int nUBucketPos = RandomInt(ADDRMAN_BUCKET_SIZE);
while (vvNew[nUBucket][nUBucketPos] == -1) {
nUBucket = (nUBucket + insecure_rand.randbits(ADDRMAN_NEW_BUCKET_COUNT_LOG2)) % ADDRMAN_NEW_BUCKET_COUNT;
nUBucketPos = (nUBucketPos + insecure_rand.randbits(ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
}
int nId = vvNew[nUBucket][nUBucketPos];
assert(mapInfo.count(nId) == 1);
CAddrInfo& info = mapInfo[nId];
if (RandomInt(1 << 30) < fChanceFactor * info.GetChance() * (1 << 30))
return info;
fChanceFactor *= 1.2;
}
}
}
开发者ID:ALEX196969,项目名称:gulden-official,代码行数:46,代码来源:addrman.cpp
示例2: TestStress3
// push_front, rotate the items
void TestStress3(int size)
{
std::cout << "\nTestStress3..." << std::endl;
CS170::List<int> list;
for (int i = 0; i < size; i++)
list.push_front(RandomInt(1, 9));
//std::cout << list;
for (int i = 0; i < size; i++)
{
list.push_back(list.front());
list.pop_front();
//std::cout << list;
}
//std::cout << list;
std::cout << "Items in the list: " << list.size() << std::endl;
std::cout << std::endl;
}
开发者ID:HBreithaupt,项目名称:DigiPenCode,代码行数:20,代码来源:driver-stress.cpp
示例3: valiant_torus
void valiant_torus( const Router_gpgpu *r, const Flit *f, int in_channel, OutputSet *outputs, bool inject )
{
int out_port;
int vc_min, vc_max;
outputs->Clear( );
if ( in_channel == 2*gN ) {
f->ph = 1; // Phase 1
f->intm = RandomInt( gNodes - 1 );
}
if ( ( f->ph == 1 ) && ( r->GetID( ) == f->intm ) ) {
f->ph = 2; // Go to phase 2
in_channel = 2*gN; // ensures correct vc selection at the beginning of phase 2
}
if ( f->ph == 1 ) { // In phase 1
dor_next_torus( r->GetID( ), f->intm, in_channel,
&out_port, &f->ring_par, false );
if ( f->ring_par == 0 ) {
vc_min = 0;
vc_max = gNumVCS/4 - 1;
} else {
vc_min = gNumVCS/4;
vc_max = gNumVCS/2 - 1;
}
} else { // In phase 2
dor_next_torus( r->GetID( ), f->dest, in_channel,
&out_port, &f->ring_par, false );
if ( f->ring_par == 0 ) {
vc_min = gNumVCS/2;
vc_max = (3*gNumVCS)/4 - 1;
} else {
vc_min = (3*gNumVCS)/4;
vc_max = gNumVCS - 1;
}
}
outputs->AddRange( out_port, vc_min, vc_max );
}
开发者ID:Urmish,项目名称:CPU-GPU-Coherence,代码行数:43,代码来源:routefunc.cpp
示例4: RandomInt
void CEnemy::Die(void)
{
int random = RandomInt( 0, 5 );
if( random == 2 )
{
GAME->SlowDownFreakingTimeBro();
CCameraControl::GetInstance()->SetKillCam(true);
}
//do we get a potion?!?
if(rand()%15 == 0)
{
CPlayer::GetInstance()->AcquirePotion();
AUDIO->SFXPlaySound(m_nGetPotionSound);
}
CBaseCharacter::Die();
m_dwDeadTimeStamp = timeGetTime();
}
开发者ID:namlunthkl,项目名称:team4-trynity,代码行数:19,代码来源:CEnemy.cpp
示例5: distrib
void Population::Mutation(void)
{
unsigned int index;
std::default_random_engine gen;
std::uniform_int_distribution<int> distrib('a', 'z');
std::uniform_real_distribution<double> distrib_d(0,1);
std::vector<char> genes;
for (std::list<Chromosome *>::iterator it = _samples.begin(); it != _samples.end(); ++it)
{
if (distrib_d(gen) <= _mutation_rate)
{
index = RandomInt(0, _gene_size);
genes = (*it)->getGenes();
genes[index] = (char)distrib(gen);
(*it)->setGenes(genes);
}
}
}
开发者ID:cesumilo,项目名称:GeneticStrings,代码行数:19,代码来源:Population.cpp
示例6: RandomInt
int ChaosRouter::_InputForOutput( int output ) const
{
// return an input that prefers this output
int input;
int offset = RandomInt( _inputs - 1 );
bool match = false;
for ( int i = 0; ( i < _inputs ) && ( !match ); ++i ) {
input = ( i + offset ) % _inputs;
if ( _InputReady( input ) &&
( ! _input_route[input]->OutputEmpty( output ) ) ) {
match = true;
}
}
return match ? input : -1;
}
开发者ID:Urmish,项目名称:CPU-GPU-Coherence,代码行数:19,代码来源:chaos_router.cpp
示例7: RandomInt
void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr)
{
unsigned int nNodes = ADDRMAN_GETADDR_MAX_PCT * vRandom.size() / 100;
if (nNodes > ADDRMAN_GETADDR_MAX)
nNodes = ADDRMAN_GETADDR_MAX;
for (unsigned int n = 0; n < vRandom.size(); n++) {
if (vAddr.size() >= nNodes)
break;
int nRndPos = RandomInt(vRandom.size() - n) + n;
SwapRandom(n, nRndPos);
assert(mapInfo.count(vRandom[n]) == 1);
const CAddrInfo& ai = mapInfo[vRandom[n]];
if (!ai.IsTerrible())
vAddr.push_back(ai);
}
}
开发者ID:Gulden,项目名称:gulden-official,代码行数:19,代码来源:addrman.cpp
示例8: game_loop
void game_loop(int low, int high)
{
int input;
do
{
int number = RandomInt(low, high);
int counter = 1;
/* Initial setup */
do
{
printf("Guess the number I'm thinking of (between %d and %d, "
"0 = quit): ", low, high);
input = get_input(low, high);
} while (input != 0 && input == -1);
while (input != number && input != 0)
{
if (number < input)
{
printf("Too high. Guess again: ");
}
else if (number > input)
{
printf("Too low. Guess again: ");
}
input = get_input(low, high);
++counter;
}
if (input)
{
printf("You guessed the number in %d tries!\n", counter);
printf("Play again? (1=yes, 0=no): ");
scanf("%d", &input);
myfflush();
}
} while (input);
}
开发者ID:beentaken,项目名称:mmeng-personal-work,代码行数:42,代码来源:human.c
示例9: GetRandomCardinalDirection
inline Direction GetRandomCardinalDirection()
{
int randomCardinalDir = RandomInt(0, 3);
switch (randomCardinalDir) {
case 0:
return EAST;
break;
case 1:
return WEST;
break;
case 2:
return SOUTH;
break;
case 3:
return NORTH;
break;
default:
return EAST;
}
}
开发者ID:2bitdreamer,项目名称:SD6_Engine,代码行数:20,代码来源:EngineCommon.hpp
示例10: CAddrInfo
CAddrInfo CAddrMan::Select_(bool newOnly)
{
if (size() == 0)
return CAddrInfo();
if (newOnly && nNew == 0)
return CAddrInfo();
if (!newOnly && (nTried > 0 && (nNew == 0 || RandomInt(2) == 0))) {
double fChanceFactor = 1.0;
while (1) {
int nKBucket = RandomInt(ADDRMAN_TRIED_BUCKET_COUNT);
int nKBucketPos = RandomInt(ADDRMAN_BUCKET_SIZE);
while (vvTried[nKBucket][nKBucketPos] == -1) {
nKBucket = (nKBucket + insecure_rand()) % ADDRMAN_TRIED_BUCKET_COUNT;
nKBucketPos = (nKBucketPos + insecure_rand()) % ADDRMAN_BUCKET_SIZE;
}
int nId = vvTried[nKBucket][nKBucketPos];
assert(mapInfo.count(nId) == 1);
CAddrInfo& info = mapInfo[nId];
if (RandomInt(1 << 30) < fChanceFactor * info.GetChance() * (1 << 30))
return info;
fChanceFactor *= 1.2;
}
} else {
double fChanceFactor = 1.0;
while (1) {
int nUBucket = RandomInt(ADDRMAN_NEW_BUCKET_COUNT);
int nUBucketPos = RandomInt(ADDRMAN_BUCKET_SIZE);
while (vvNew[nUBucket][nUBucketPos] == -1) {
nUBucket = (nUBucket + insecure_rand()) % ADDRMAN_NEW_BUCKET_COUNT;
nUBucketPos = (nUBucketPos + insecure_rand()) % ADDRMAN_BUCKET_SIZE;
}
int nId = vvNew[nUBucket][nUBucketPos];
assert(mapInfo.count(nId) == 1);
CAddrInfo& info = mapInfo[nId];
if (RandomInt(1 << 30) < fChanceFactor * info.GetChance() * (1 << 30))
return info;
fChanceFactor *= 1.2;
}
}
}
开发者ID:Gulden,项目名称:gulden-official,代码行数:44,代码来源:addrman.cpp
示例11: RandomInt
void TransactionHandler::callRandom(const unsigned int pTimes)
{
//std::lock_guard<std::mutex> locker(m);
size_t s = mTransactions.size();
if (s > 0)
{
for (int i = 0; i < pTimes; i++)
{
//m.lock();
int random = RandomInt((int)mTransactions.size());
Transaction* t = new Transaction(mTransactions[random]);
t->call(); //local variable
delete t;
//m.unlock();
//mTransactions[random].call();
}
}
}
开发者ID:Fibonacho,项目名称:Concurrency-Control-Manager,代码行数:20,代码来源:TransactionHandler.cpp
示例12: Find
void CAddrMan::Good_(const CService& addr, int64_t nTime)
{
int nId;
nLastGood = nTime;
CAddrInfo* pinfo = Find(addr, &nId);
if (!pinfo)
return;
CAddrInfo& info = *pinfo;
if (info != addr)
return;
info.nLastSuccess = nTime;
info.nLastTry = nTime;
info.nAttempts = 0;
if (info.fInTried)
return;
int nRnd = RandomInt(ADDRMAN_NEW_BUCKET_COUNT);
int nUBucket = -1;
for (unsigned int n = 0; n < ADDRMAN_NEW_BUCKET_COUNT; n++) {
int nB = (n + nRnd) % ADDRMAN_NEW_BUCKET_COUNT;
int nBpos = info.GetBucketPosition(nKey, true, nB);
if (vvNew[nB][nBpos] == nId) {
nUBucket = nB;
break;
}
}
if (nUBucket == -1)
return;
LogPrint("addrman", "Moving %s to tried\n", addr.ToString());
MakeTried(info, nId);
}
开发者ID:Gulden,项目名称:gulden-official,代码行数:41,代码来源:addrman.cpp
示例13: SelectWeightedSequence
int SelectWeightedSequence( CStudioHdr *pstudiohdr, int activity, int curSequence )
{
VPROF( "SelectWeightedSequence" );
if (! pstudiohdr)
return 0;
if (!pstudiohdr->SequencesAvailable())
return 0;
VerifySequenceIndex( pstudiohdr );
int weighttotal = 0;
int seq = ACTIVITY_NOT_AVAILABLE;
int weight = 0;
for (int i = 0; i < pstudiohdr->GetNumSeq(); i++)
{
int curActivity = GetSequenceActivity( pstudiohdr, i, &weight );
if (curActivity == activity)
{
if ( curSequence == i && weight < 0 )
{
seq = i;
break;
}
weighttotal += iabs(weight);
int randomValue;
if ( IsInPrediction() )
randomValue = SharedRandomInt( "SelectWeightedSequence", 0, weighttotal - 1, i );
else
randomValue = RandomInt( 0, weighttotal - 1 );
if (!weighttotal || randomValue < iabs(weight))
seq = i;
}
}
return seq;
}
开发者ID:TotallyMehis,项目名称:ZM-Updated,代码行数:41,代码来源:animation.cpp
示例14: DETOUR_DECL_MEMBER
DETOUR_DECL_MEMBER(ActionResult<CTFBot>, CTFBotMvMEngineerIdle_Update, CTFBot *actor, float dt)
{
SCOPED_INCREMENT(rc_CTFBotMvMEngineerIdle_Update);
TRACE();
static IntervalTimer last_ask;
constexpr float ask_interval = 20.0f;
constexpr float ask_minwait = 3.0f;
if (RandomFloat(0.0f, 1.0f) < (dt / ask_interval)) {
if (last_ask.GetElapsedTime() > ask_minwait) {
last_ask.Start();
switch (RandomInt(0, 2)) {
case 0:
case 1:
actor->SpeakConceptIfAllowed(MP_CONCEPT_PLAYER_TELEPORTERHERE);
break;
case 2:
actor->SpeakConceptIfAllowed(MP_CONCEPT_PLAYER_SENTRYHERE);
break;
}
}
}
auto result = DETOUR_MEMBER_CALL(CTFBotMvMEngineerIdle_Update)(actor, dt);
if (result.transition == ActionTransition::SUSPEND_FOR && result.action != nullptr) {
if (strcmp(result.action->GetName(), "MvMEngineerBuildSentryGun") == 0 && hint_sg != nullptr) {
delete result.action;
result.action = new CTFBotMvMEngineerBuildSGDispenser(hint_sg);
hint_sg = nullptr;
} else if (strcmp(result.action->GetName(), "MvMEngineerBuildTeleportExit") == 0 && hint_te != nullptr) {
delete result.action;
result.action = new CTFBotMvMEngineerBuildTEDispenser(hint_te);
hint_te = nullptr;
}
}
return result;
}
开发者ID:sigsegv-mvm,项目名称:sigsegv-mvm,代码行数:41,代码来源:engiebot_dispensers.cpp
示例15: BeginPlayback
void CASW_Video::OnVideoOver()
{
if ( m_bIsTransition )
{
m_bIsTransition = false;
BeginPlayback( m_nLastTempVideo );
}
else if ( !m_bIsLoopVideo )
{
m_bIsLoopVideo = true;
BeginPlayback( m_nLoopVideo );
}
else if ( m_nNumLoopAlternatives > 0 && RandomFloat() < m_fAlternateChance )
{
PlayTempVideo( m_nLoopVideo + RandomInt( 1, m_nNumLoopAlternatives ) );
}
else
{
bik->SetFrame( GetVideoFaceBIKHandles()->GetBIKHandle( m_nLoopVideo ), 0.0f );
}
}
开发者ID:Au-heppa,项目名称:swarm-sdk,代码行数:21,代码来源:asw_video.cpp
示例16: TestStress4
// push_front, subscript
void TestStress4(int size, int value)
{
std::cout << "\nTestStress4..." << std::endl;
CS170::List list;
for (int i = 0; i < size; i++)
list.push_front(RandomInt(1, 9));
//std::cout << list;
int count = 0;
for (int i = 0; i < size; i++)
{
if (list[i] == value)
count++;
}
std::cout << "Items in the list: " << list.size() << std::endl;
std::cout << "The number " << value << " appears " << count
<< " times in the list" << std::endl;
std::cout << std::endl;
}
开发者ID:HBreithaupt,项目名称:DigiPenCode,代码行数:22,代码来源:driver-stress.cpp
示例17: assert
int HotSpotTrafficPattern::dest(int source)
{
assert((source >= 0) && (source < _nodes));
if(_hotspots.size() == 1) {
return _hotspots[0];
}
int pct = RandomInt(_max_val);
for(size_t i = 0; i < (_hotspots.size() - 1); ++i) {
int const limit = _rates[i];
if(limit > pct) {
return _hotspots[i];
} else {
pct -= limit;
}
}
assert(_rates.back() > pct);
return _hotspots.back();
}
开发者ID:DINKIN,项目名称:booksim2,代码行数:21,代码来源:traffic.cpp
示例18:
void CTF2UpgradeObjectEvent::Execute(IBotEventInterface *pEvent)
{
if (bot_use_vc_commands.GetBool() && RandomInt(0, 1))
{
eEngiBuild object = (eEngiBuild)pEvent->GetInt("object", 0);
bool isbuilder = (pEvent->GetInt("isbuilder") > 0);
short index = pEvent->GetInt("index");
if (!isbuilder)
{
// see if builder is a bot
edict_t *pOwner = CTeamFortress2Mod::GetBuildingOwner(object, index);
CBotTF2 *pBot;
if ((pBot = (CBotTF2*)CBots::GetBotPointer(pOwner)) != NULL)
{
pBot->AddVoiceCommand(TF_VC_THANKS);
}
}
}
}
开发者ID:Deathreus,项目名称:AFKBot,代码行数:21,代码来源:bot_events.cpp
示例19: RandomInt
void
Powerup::manifest (void)
{
if (random)
{
type = RandomInt (0, MAX_POWERUP);
}
SetModel (models[type]);
RemoveEffects (EF_NODRAW);
SetSolid (SOLID_BBOX);
AddSolidFlags (FSOLID_TRIGGER);
SetMoveType (MOVETYPE_NONE);
UTIL_SetSize (this, -Vector (32,32,32), Vector (32,32,32));
SetThink (NULL);
SetTouch (&Powerup::pickup);
CPASFilter filter (GetAbsOrigin ());
filter.UsePredictionRules ();
EmitSound (filter, entindex (), "Item.Materialize");
}
开发者ID:Black-Stormy,项目名称:DoubleAction,代码行数:21,代码来源:da_powerup.cpp
示例20: RandomInt
// picks a number of spawners randomly from this spawngroup
void CASW_Spawn_Group::PickSpawnersRandomly( int nNumSpawners, bool bIncludeRecentlySpawned, CUtlVector< CASW_Base_Spawner* > *pSpawners )
{
pSpawners->RemoveAll();
CUtlVector< CASW_Base_Spawner* > candidates;
for ( int i = 0; i < m_hSpawners.Count(); i++ )
{
if ( !m_hSpawners[i].Get() || !m_hSpawners[i]->IsEnabled() )
continue;
if ( !bIncludeRecentlySpawned && m_hSpawners[i]->HasRecentlySpawned() )
continue;
candidates.AddToTail( m_hSpawners[i].Get() );
}
for ( int i = 0; ( (i < nNumSpawners) && (candidates.Count() > 0) ); i++ )
{
int nChosen = RandomInt( 0, candidates.Count() - 1 );
pSpawners->AddToTail( candidates[ nChosen ] );
candidates.Remove( nChosen );
}
}
开发者ID:BenLubar,项目名称:SwarmDirector2,代码行数:23,代码来源:asw_spawn_group.cpp
注:本文中的RandomInt函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论