本文整理匯總了C++中GetRandom函數的典型用法代碼示例。如果您正苦於以下問題:C++ GetRandom函數的具體用法?C++ GetRandom怎麽用?C++ GetRandom使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GetRandom函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: defined
// ----------------------------------------------------------------------- //
//
// ROUTINE: CSoundSet::GetRandomFile()
//
// PURPOSE: Get a random sound from the set
//
// ----------------------------------------------------------------------- //
const char* CSoundSet::GetRandomFile()
{
//if we're not set up or we have no files, bail
if (!m_hRecord || !m_nTotalWeight || !m_vecWeights.size())
return "";
#if defined(PLATFORM_WIN32) || defined(PLATFORM_LINUX)
HATTRIBUTE hFiles = g_pLTDatabase->GetAttribute(m_hRecord,SndDB_sSoundFile);
//only got one, return it
if (m_vecWeights.size() == 1)
return g_pLTDatabase->GetString(hFiles,0,"");
uint32 nRand = GetRandom(0,m_nTotalWeight-1);
for (uint32 n = 0; n < m_vecWeights.size(); ++n)
{
if (nRand < m_vecWeights[n])
return g_pLTDatabase->GetString(hFiles,n,"");
}
//if we got this far, just return the first value
return g_pLTDatabase->GetString(hFiles,0,"");
#endif // PLATFORM_WIN32 || PLATFORM_LINUX
#ifdef PLATFORM_XENON
HATTRIBUTE hCue = g_pLTDatabase->GetAttribute(m_hRecord,SndDB_sXActCue);
if (hCue)
{
return g_pLTDatabase->GetString(hCue,0,"");
}
else
{
return "";
}
#endif // PLATFORM_XENON
}
示例2: GetRandom
bool CMusicMgr::SetMood( Mood eMood )
{
char szMusic[128];
uint32 iLevel = GetRandom(0, m_acMoods[eMood]-1);
sprintf(szMusic, "MUSIC I %d measure", m_aanMoods[eMood][iLevel]);
#ifndef _FINAL
if ( g_ShowMusicTrack.GetFloat() > 0 )
{
g_pLTServer->CPrint("Server sending client Music Message: (%s)", szMusic);
}
#endif
HSTRING hMusic = g_pLTServer->CreateString(szMusic);
CAutoMessage cMsg;
cMsg.Writeuint8(MID_MUSIC);
cMsg.WriteHString(hMusic);
g_pLTServer->SendToClient(cMsg.Read(), LTNULL, MESSAGE_GUARANTEED);
FREE_HSTRING(hMusic);
m_eLastMood = eMood;
return true;
}
示例3: GetRandom
// ----------------------------------------------------------------------- //
//
// ROUTINE: CSoundSet::GetRandomAltFile()
//
// PURPOSE: Get a random alternate sound from the set
//
// ----------------------------------------------------------------------- //
const char* CSoundSet::GetRandomAltFile()
{
//if we're not set up or we have no files, bail
if (!m_hRecord || !m_nAltTotalWeight || !m_vecAltWeights.size())
return "";
HATTRIBUTE hFiles = g_pLTDatabase->GetAttribute(m_hRecord,SndDB_sAltSoundFile);
//only got one, return it
if (m_vecAltWeights.size() == 1)
return g_pLTDatabase->GetString(hFiles,0,"");
uint32 nRand = GetRandom(0,m_nAltTotalWeight-1);
for (uint32 n = 0; n < m_vecAltWeights.size(); ++n)
{
if (nRand < m_vecAltWeights[n])
return g_pLTDatabase->GetString(hFiles,n,"");
}
//if we got this far, just return the first value
return g_pLTDatabase->GetString(hFiles,0,"");
}
示例4: GetCurrentExposureTime
//
// Translate Exposure settings into a "current value".
//
LONGLONG
CHardwareSimulation::
GetCurrentExposureTime()
{
PAGED_CODE();
ISP_FRAME_SETTINGS *pSettings = GetIspSettings();
LONGLONG Value = 0;
LPCSTR Mode = "[UNKNOWN]";
if( pSettings->ExposureMode & KSCAMERA_EXTENDEDPROP_VIDEOPROCFLAG_AUTO )
{
// Get random value in global setting's bound (LONG)
// I'm abandoning the reported min/max and using something more reasonable.
Value = GetRandom( MIN_EXPOSURE_TIME*5, DEF_EXPOSURE_TIME*5 );
Mode = "KSCAMERA_EXTENDEDPROP_VIDEOPROCFLAG_AUTO";
}
if( pSettings->ExposureMode & KSCAMERA_EXTENDEDPROP_VIDEOPROCFLAG_MANUAL )
{
Value = pSettings->ExposureSetting.VideoProc.Value.ll;
Mode = "KSCAMERA_EXTENDEDPROP_VIDEOPROCFLAG_MANUAL";
}
// Locked just reports the last value set...
if( pSettings->ExposureMode & KSCAMERA_EXTENDEDPROP_VIDEOPROCFLAG_LOCK )
{
Value = m_LastReportedExposureTime;
Mode = "KSCAMERA_EXTENDEDPROP_VIDEOPROCFLAG_LOCK";
}
DBG_TRACE("ExposureMode=0x%016llX (%s), Time=%llu00ns, LastReported=%llu00ns",
pSettings->ExposureMode, Mode, Value, m_LastReportedExposureTime );
m_LastReportedExposureTime = Value;
return Value;
}
示例5: ASSERT
SEARCH_SET::SearchObjectType SEARCH_SET::GetRandomSearchObjectType(float fJunkModifier)
{
if (fJunkModifier < 0.0f || fJunkModifier > 1.0f)
{
ASSERT(!"SEARCH_SET::GetRandomSearchObjectType(): bad skill modifier");
fJunkModifier = 1.0f;
}
//reduce the chance of random junk
uint8 nJunkChance = (uint8)( (float)nItemPercent * fJunkModifier );
//figure out a new total
uint8 nTotal = 100 - (nItemPercent - nJunkChance);
//roll the die...
uint8 nRandVal = GetRandom(1, nTotal);
SearchObjectType eType = eUnknownObjectType;
if (nRandVal <= nJunkChance)
{
eType = eItemObjectType;
}
else if (nRandVal <= nJunkChance + nAmmoPercent)
{
eType = eAmmoObjectType;
}
else if (nRandVal <= nJunkChance + nAmmoPercent + nWeaponPercent)
{
eType = eWeaponObjectType;
}
else
{
eType = eGearObjectType;
}
return eType;
}
示例6: InitializeShell
bool __CALLOUT InitializeShell() {
Clear(BLUE);
const char* str = "PRICE of HONOR!";
DrawTextString(40,60,str,Length(str),RED,BLUE);
GetBatteryLevel();
SetScreenBrightness(100);
char buff[200];
int res = snprintf(buff,sizeof(buff),"test %d",0);
DrawPixel(1,1,WHITE);
DoVibroAndBeep(500);
ubyte_t l = GetLustraId();
SendRadioPacket(NULL,0);
uword_t a = GetArmletId();
FILE log;
OpenFile(&log, "log.txt", true);
char* s = "log test";
WriteFile(&log, s, Length(s));
/*
//int i = 0;
//Color area[100];
//for (i=0; i<100; i++) area[i] = 0xF0F;
//DrawArea(5,5,area,100,10,10);
//WriteFile(&log, (char*)area, 100);
//for (i=0; i<100; i++) area[i] = 0x0;
//ReadFile(&log, (char*)area, 100);
//AppendFile(&log, (char*)area, 100);
//DrawArea(5,5,area,100,10,10);
*/
RequestTimer(TimerProc,100);
int up = GetUpTime();
int rnd = GetRandom(50);
//SetCureName is checked in AppMainThread
//WritePill is checked in AppMainThread
//StartThread(AppMainThread,NULL);
return true; //TODO
}
示例7: GetCurrentISOSpeed
//
// Translate ISO settings into a "current value".
//
ULONG
CHardwareSimulation::
GetCurrentISOSpeed()
{
PAGED_CODE();
ISP_FRAME_SETTINGS *pSettings = GetIspSettings();
ULONG Value = 0;
if( pSettings->ISOMode & KSCAMERA_EXTENDEDPROP_ISO_AUTO )
{
Value = GetRandom( (ULONG) 50, (ULONG) 3200 );
}
else if( pSettings->ISOMode & KSCAMERA_EXTENDEDPROP_ISO_MANUAL )
{
Value = pSettings->ISOValue;
}
else
{
Value = // Try converting any legacy presets to a manual value.
IsoPreset2Value( pSettings->ISOMode );
}
return Value;
}
示例8: psGetRandom
void Reaction::DeepCopy(Reaction& other,BehaviorSet& behaviors)
{
desireValue = other.desireValue;
desireType = other.desireType;
for (size_t i = 0; i < other.affected.GetSize(); i++)
{
Behavior * behavior = behaviors.Find(other.affected[i]->GetName());
affected.Push(behavior);
}
eventType = other.eventType;
range = other.range;
factionDiff = other.factionDiff;
oper = other.oper;
weight = other.weight;
values = other.values;
valuesValid = other.valuesValid;
randoms = other.randoms;
randomsValid = other.randomsValid;
type = other.type;
activeOnly = other.activeOnly;
inactiveOnly = other.inactiveOnly;
reactWhenDead = other.reactWhenDead;
reactWhenInvisible = other.reactWhenInvisible;
reactWhenInvincible = other.reactWhenInvincible;
onlyInterrupt = other.onlyInterrupt;
doNotInterrupt = other.doNotInterrupt;
// For now depend on that each npc do a deep copy to create its instance of the reaction
for (uint ii=0; ii < values.GetSize(); ii++)
{
if (GetRandomValid((int)ii))
{
values[ii] += psGetRandom(GetRandom((int)ii));
}
}
}
示例9: main
int main(int argc, char *argv[])
{
FILE* fp;
unsigned int i;
struct data_t data;
if (argc != 3) {
printf("## Data Generator for 310_sort Ver.2013-10-13\n");
printf("## Usage: ./data_gen i random_seed\n");
printf("## : n = i * 1024n");
exit(1);
}
int random_seed = atoi(argv[2]);
srand(random_seed);
fp = fopen("310sort.txt", "wb");
if (fp==NULL) { fputs("fail to open\n", stderr); exit(1); }
for (i=0; i<SIZE-1; i++){
data.buf[i] = GetRandom();
// printf("%d\n", data.buf[i]);
}
data.n = atoi(argv[1]) * 1024;
//fwrite(&data, sizeof(unsigned int), SIZE, fp);
for (i=0;i<SIZE-1; i++){
fprintf(fp, "%d,",data.buf[i]);
}
fprintf(fp, "%d,\n",data.n);
fclose(fp);
return 0;
}
示例10: GetRandom
void CBaseParticleSystemFX::GetRandomColorInRange(DVector & vColor)
{
DFLOAT fColorR = GetRandom(m_vColor1.x, m_vColor2.x);
// Kludge the color for software...
if (m_bSetSoftwareColor)
{
m_pClientDE->SetSoftwarePSColor(m_hObject, m_vColor1.x/255.0f, m_vColor1.y/255.0f, m_vColor1.z/255.0f);
}
if (m_vColorRange.x <= 0.0f)
{
VEC_COPY(vColor, m_vColor1);
}
else
{
vColor.x = fColorR;
vColor.y = (m_vColorRange.y * fColorR) / m_vColorRange.x;
vColor.z = (m_vColorRange.z * fColorR) / m_vColorRange.x;
}
return;
}
示例11: SampleSobol
static void SampleSobol(cSamples *samples, cBounds *b, creal vol)
{
creal norm = vol*samples->weight;
real *x = samples->x, *f = samples->f, *avg = samples->avg;
ccount n = samples->n;
count i, dim, comp;
for( i = 0; i < n; ++i ) {
GetRandom(x);
for( dim = 0; dim < ndim_; ++x, ++dim )
*x = b[dim].lower + *x*(b[dim].upper - b[dim].lower);
}
DoSample(n, ndim_, samples->x, f);
ResCopy(avg, f);
f += ncomp_;
for( i = 1; i < n; ++i )
for( comp = 0; comp < ncomp_; ++comp )
avg[comp] += *f++;
for( comp = 0; comp < ncomp_; ++comp )
avg[comp] *= norm;
}
示例12: Bleed
void Bleed (edict_t *curse)
{
int take;
edict_t *caster=curse->owner;
if (curse->atype != BLEEDING)
return;
if (level.time < curse->wait)
return;
if (!G_ValidTarget(caster, curse->enemy, false))
{
// remove the curse if the target dies
que_removeent(curse->enemy->curses, curse, true);
return;
}
// 33-99% health taken over duration of curse
take = (curse->enemy->max_health * (0.033 * curse->monsterinfo.level)) / curse->monsterinfo.selected_time;
//gi.dprintf("target %s take %d health %d/%d level %d time %.1f\n",
// curse->enemy->classname, take, curse->enemy->health, curse->enemy->max_health,
// curse->monsterinfo.level, curse->monsterinfo.selected_time);
// damage limits
if (take < 1)
take = 1;
if (take > 100)
take = 100;
T_Damage(curse->enemy, caster, caster, vec3_origin, vec3_origin,
vec3_origin, take, 0, DAMAGE_NO_ABILITIES, MOD_LIFE_DRAIN);
curse->wait = level.time + (GetRandom(3, 10) * FRAMETIME);
}
示例13: main
int main(int argc, const char** argv)
{
const uint NUM_SHIPS = 50;
const uint NUM_PLANETS = 500;
const uint FIELD_DIMS = 500;
GraphManager GraphManager;
GraphManager.CreateGraph(NUM_PLANETS, { FIELD_DIMS, FIELD_DIMS });
GraphManager.FormEdges();
std::vector<Planet*> PlanetList;
for (uint i = 0; i < GraphManager.NumNodes(); ++i)
{
Planet* p = new Planet(i, GraphManager.TakeNode());
PlanetList.push_back(p);
}
std::vector<Ship> ShipList;
for (uint i = 0; i < NUM_SHIPS; ++i)
{
ShipList.emplace_back(i, PlanetList[GetRandom(0, NUM_PLANETS)], [&] (GraphNode* Start, GraphNode* End)
{
auto GraphList = GraphManager.FindPath(Start, End);
std::vector<Planet*> Result;
for(auto Node : GraphList)
for (Planet* Planet : PlanetList)
if (Planet->GetGraphNode() == Node)
Result.push_back(Planet);
return Result;
});
}
for (auto& Ship : ShipList)
Ship.Tick(PlanetList);
return 0;
}
示例14: SelectFlamePotPosition
// Returns true if the AI has a valid flame pot position for this link, false
// if it does not.
//
// Helper function for setting a flame pot position. If the AI already has
// a valid position, it will use it. If the AI does not have a valid
// position, a new position will be selected.
static bool SelectFlamePotPosition( CAI* pAI, AINavMeshLinkAbstract* pLink )
{
// Sanity checks.
if ( !pAI || !pLink )
{
return false;
}
//
// Check to see if the AI already has a position. If he does, use it.
//
CAIWMFact queryExistingFact;
queryExistingFact.SetFactType( kFact_Knowledge );
queryExistingFact.SetKnowledgeType( kKnowledge_FlamePotPosition );
queryExistingFact.SetSourceObject( pAI->GetAIBlackBoard()->GetBBTargetObject() );
queryExistingFact.SetTargetObject( pLink->GetHOBJECT() );
CAIWMFact* pCurrentPosition = pAI->GetAIWorkingMemory()->FindWMFact( queryExistingFact );
if ( NULL != pCurrentPosition )
{
// Ignore the point if the AI is already very close to it; this is
// likely an old position that was 'achieved'.
LTVector vPosDelta2D = ( pAI->GetPosition() - pCurrentPosition->GetPos() );
vPosDelta2D.y = 0.0f;
float flDistanceSqr2D = vPosDelta2D.MagSqr();
if ( flDistanceSqr2D >= g_flCirclingPositionAchievedDistSqr )
{
return true;
}
}
CAINavMeshPoly* pPoly = g_pAINavMesh->GetNMPoly( pLink->GetNMPolyID() );
if ( NULL == pPoly )
{
return false;
}
// Get the total length of the edge, so we can pick a number within the
// range [0, EdgeLength]
int nEdges = pPoly->GetNumNMPolyEdges();
float flEdgeLengthSum = 0.0f;
for ( int i = 0; i < nEdges; ++i )
{
// Skip any edges which:
// 1) Don't exist.
// 2) Don't have polies on both sides.
CAINavMeshEdge* pEdge = pPoly->GetNMPolyEdge( i );
if ( !pEdge
|| kNMPoly_Invalid == pEdge->GetNMPolyIDA()
|| kNMPoly_Invalid == pEdge->GetNMPolyIDB() )
{
continue;
}
flEdgeLengthSum += ( pEdge->GetNMEdge0() - pEdge->GetNMEdge1() ).Mag(); // TODO: Don't need to get the mag here.
}
// Fail if there are no valid positions.
float flRandomDistanceAlongEdge = GetRandom( 0.0f, flEdgeLengthSum );
if ( 0.0f == flRandomDistanceAlongEdge )
{
return false;
}
//
// Select a position on the edge.
//
bool bFoundPosition = false;
LTVector vSelectedPosition;
float flRemainingDistance = flRandomDistanceAlongEdge;
for ( int i = 0; i < nEdges; ++i )
{
// Skip any edges which:
// 1) Don't exist.
// 2) Don't have polies on both sides.
CAINavMeshEdge* pEdge = pPoly->GetNMPolyEdge( i );
if ( !pEdge
|| kNMPoly_Invalid == pEdge->GetNMPolyIDA()
|| kNMPoly_Invalid == pEdge->GetNMPolyIDB() )
{
continue;
}
float flEdgeLength = ( pEdge->GetNMEdge0() - pEdge->GetNMEdge1() ).Mag(); // TODO: Don't need to get the mag here.
if ( flRemainingDistance < flEdgeLength )
{
// Find the distance along the edge for the position.
LTVector vEdgeDir = ( pEdge->GetNMEdge1() - pEdge->GetNMEdge0() ).GetUnit();
//.........這裏部分代碼省略.........
示例15: IsPlayer
void CAIGoalCircleFlamePot::DeactivateGoal()
{
super::DeactivateGoal();
// If:
// 1) The player is an enemy.
// 2) There is another AI very close by
// 3) That AI does not have a blitz task
// ...this AI should blitz the player. This is an anti-clumping measure.
HOBJECT hTarget = m_pAI->GetAIBlackBoard()->GetBBTargetObject();
bool bShouldBlitz = false;
if ( m_pAI->HasTarget( kTarget_Character )
&& IsPlayer( hTarget ) )
{
CAI::AIList::const_iterator itEachAI = CAI::GetAIList().begin();
CAI::AIList::const_iterator itLastAI = CAI::GetAIList().end();
for ( ; itEachAI != itLastAI; ++itEachAI )
{
CAI* pCurrentAI = *itEachAI;
// Ignore NULL, self and dead AI.
if ( NULL == pCurrentAI
|| pCurrentAI == m_pAI
|| IsDeadAI( pCurrentAI->GetHOBJECT() ) )
{
continue;
}
// Ignore AIs who are far away in 2D (false positives are okay).
LTVector vDelta2D = ( pCurrentAI->GetPosition() - m_pAI->GetPosition() );
vDelta2D.y = 0.0f;
if ( vDelta2D.MagSqr() > g_flTooCloseToEnemySqr )
{
continue;
}
// Ignore AI who are already blitzing.
CAIWMFact factQuery;
factQuery.SetFactType( kFact_Task );
factQuery.SetTaskType( kTask_BlitzCharacter );
if ( pCurrentAI->GetAIWorkingMemory()->FindWMFact( factQuery ) )
{
continue;
}
// AI should blitz.
bShouldBlitz = true;
break;
}
}
if ( bShouldBlitz || ( 0 == GetRandom( 0, 2 ) ) )
{
CAIWMFact factQuery;
factQuery.SetFactType( kFact_Task );
factQuery.SetTaskType( kTask_BlitzCharacter );
CAIWMFact* pFact = m_pAI->GetAIWorkingMemory()->CreateWMFact( kFact_Task );
if ( pFact )
{
pFact->SetTaskType( kTask_BlitzCharacter );
pFact->SetTargetObject( hTarget );
pFact->SetIndex( kContext_None );
pFact->SetFactFlags( kFactFlag_Scripted, 1.f );
}
}
}