本文整理汇总了C++中RandomSeed函数的典型用法代码示例。如果您正苦于以下问题:C++ RandomSeed函数的具体用法?C++ RandomSeed怎么用?C++ RandomSeed使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RandomSeed函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RandomIntLong
void RandomPermutationTrafficPattern::randomize(int seed)
{
unsigned long prev_seed = RandomIntLong( );
RandomSeed(seed);
_dest.assign(_nodes, -1);
for(int i = 0; i < _nodes; ++i) {
int ind = RandomInt(_nodes - 1 - i);
int j = 0;
int cnt = 0;
while((cnt < ind) || (_dest[j] != -1)) {
if(_dest[j] == -1) {
++cnt;
}
++j;
assert(j < _nodes);
}
_dest[j] = i;
}
RandomSeed(prev_seed);
}
示例2: _InitializeGlobals
static void _InitializeGlobals(int argc, char *argv[]) {
char fileName[255];
_processArgs(argc, argv);
MSetAllocFailFunction(_AllocFailed);
if(gUseStartingNet) {
gPriorNet = BNReadBIF(gStartingNetFile);
if(gPriorNet == 0) {
DebugError(1, "couldn't read net specified by -startFrom\n");
}
gEs = BNGetExampleSpec(gPriorNet);
} else {
sprintf(fileName, "%s/%s.names", gSourceDirectory, gFileStem);
gEs = ExampleSpecRead(fileName);
DebugError(gEs == 0, "Unable to open the .names file");
gPriorNet = BNNewFromSpec(gEs);
}
gInitialParameterCount = BNGetNumParameters(gPriorNet);
gBranchFactor = BNGetNumNodes(gPriorNet) * BNGetNumNodes(gPriorNet);
if(gLimitBytes != -1) {
gMaxBytesPerModel = gLimitBytes / BNGetNumNodes(gPriorNet);
//gMaxBytesPerModel = gLimitBytes / gBranchFactor;
DebugMessage(1, 2, "Limit models to %.4lf megs\n",
gMaxBytesPerModel / (1024.0 * 1024.0));
}
gCurrentNet = BNClone(gPriorNet);
BNZeroCPTs(gCurrentNet);
RandomInit();
/* seed */
if(gSeed != -1) {
RandomSeed(gSeed);
} else {
gSeed = RandomRange(1, 30000);
RandomSeed(gSeed);
}
DebugMessage(1, 1, "running with seed %d\n", gSeed);
DebugMessage(1, 1, "allocation %ld\n", MGetTotalAllocation());
DebugMessage(1, 1, "initial parameters %ld\n", gInitialParameterCount);
}
示例3: RandomSeed
//----------------------------------------
void SingleRandom::Generate()
{
int loop, offset;
table_.clear();
for(loop = range_min_; loop < range_max_; ++loop)
{
table_.push_back(loop);
}
int tem;
RandomSeed();
for(loop = 0; loop < table_.size(); ++loop)
{
offset = NormalRandom(0, table_.size() - 1) + loop;
//offset = (rand() % (range_max_ - 1)) + loop;
if( offset >= table_.size())
offset -= table_.size();
//将数字对调
tem = table_[loop];
table_[loop] = table_[offset];
table_[offset] = tem;
}
}
示例4: RandomSeedAuto
void RandomSeedAuto(void) {
EFI_TIME t;
RT->GetTime(&t, 0);
UINT64 a, b = ((((((UINT64) t.Second * 100 + t.Minute) * 100 + t.Hour) * 100 + t.Day) * 100 + t.Month) * 10000 + t.Year) * 300000 + t.Nanosecond;
BS->GetNextMonotonicCount(&a);
RandomSeed(a, b), Random(), Random();
}
示例5: SaveRandomState
void RandomPermutationTrafficPattern::randomize(int seed)
{
vector<long> save_x;
vector<double> save_u;
SaveRandomState(save_x, save_u);
RandomSeed(seed);
_dest.assign(_nodes, -1);
for(int i = 0; i < _nodes; ++i) {
int ind = RandomInt(_nodes - 1 - i);
int j = 0;
int cnt = 0;
while((cnt < ind) || (_dest[j] != -1)) {
if(_dest[j] == -1) {
++cnt;
}
++j;
assert(j < _nodes);
}
_dest[j] = i;
}
RestoreRandomState(save_x, save_u);
}
示例6: SharedRandomInt
int SharedRandomInt( const char *sharedname, int iMinVal, int iMaxVal, int additionalSeed /*=0*/ )
{
Assert( CBaseEntity::GetPredictionRandomSeed() != -1 );
int seed = SeedFileLineHash( CBaseEntity::GetPredictionRandomSeed(), sharedname, additionalSeed );
RandomSeed( seed );
return RandomInt( iMinVal, iMaxVal );
}
示例7: SharedRandomFloat
//-----------------------------------------------------------------------------
// Purpose: Accessed by SHARED_RANDOMFLOAT macro to get c/s neutral random float for prediction
// Input : *filename -
// line -
// flMinVal -
// flMaxVal -
// Output : float
//-----------------------------------------------------------------------------
float SharedRandomFloat( const char *filename, int line, float flMinVal, float flMaxVal, int additionalSeed /*=0*/ )
{
Assert( C_BaseEntity::GetPredictionRandomSeed() != -1 );
int seed = SeedFileLineHash( C_BaseEntity::GetPredictionRandomSeed(), filename, line, additionalSeed );
RandomSeed( seed );
return RandomFloat( flMinVal, flMaxVal );
}
示例8: CryptoInitialize
void CryptoInitialize()
{
if (!crypto_initialized)
{
SetupOpenSSLThreadLocks();
OpenSSL_add_all_algorithms();
OpenSSL_add_all_digests();
ERR_load_crypto_strings();
RandomSeed();
crypto_initialized = true;
}
}
示例9: SharedRandomVector
Vector SharedRandomVector( const char *sharedname, float minVal, float maxVal, int additionalSeed /*=0*/ )
{
Assert( CBaseEntity::GetPredictionRandomSeed() != -1 );
int seed = SeedFileLineHash( CBaseEntity::GetPredictionRandomSeed(), sharedname, additionalSeed );
RandomSeed( seed );
// HACK: Can't call RandomVector/Angle because it uses rand() not vstlib Random*() functions!
// Get a random vector.
Vector random;
random.x = RandomFloat( minVal, maxVal );
random.y = RandomFloat( minVal, maxVal );
random.z = RandomFloat( minVal, maxVal );
return random;
}
示例10: UpdateBenchmark
virtual void UpdateBenchmark()
{
// No benchmark running?
if ( m_BenchmarkState == BENCHMARKSTATE_NOT_RUNNING )
return;
// Wait a certain number of ticks to start the benchmark.
if ( m_BenchmarkState == BENCHMARKSTATE_START_WAIT )
{
if ( (Plat_FloatTime() - m_flBenchmarkStartTime) < m_flBenchmarkStartWaitTime )
{
UpdateStartWaitCounter();
return;
}
else
{
// Ok, now we're officially starting it.
Msg( "Starting benchmark!\n" );
m_flLastBenchmarkCounterUpdate = m_flBenchmarkStartTime = Plat_FloatTime();
m_fl_ValidTime_BenchmarkStartTime = Benchmark_ValidTime();
m_nBenchmarkStartTick = gpGlobals->tickcount;
m_nLastPhysicsObjectTick = m_nLastPhysicsForceTick = 0;
m_BenchmarkState = BENCHMARKSTATE_RUNNING;
StartVProfRecord();
RandomSeed( 0 );
m_RandomStream.SetSeed( 0 );
}
}
int nTicksRunSoFar = gpGlobals->tickcount - m_nBenchmarkStartTick;
UpdateBenchmarkCounter();
// Are we finished with the benchmark?
if ( nTicksRunSoFar >= sv_benchmark_numticks.GetInt() )
{
EndVProfRecord();
OutputResults();
EndBenchmark();
return;
}
// Ok, update whatever we're doing in the benchmark.
UpdatePlayerCreation();
UpdateVPhysicsObjects();
CServerBenchmarkHook::s_pBenchmarkHook->UpdateBenchmark();
}
示例11: EmitDetailObjects
//-----------------------------------------------------------------------------
// Places Detail Objects in the level
//-----------------------------------------------------------------------------
void EmitDetailObjects()
{
// Guarantee identical random emission...
srand(1);
RandomSeed( 1 );
EmitDetailModels();
// Done! Now lets add the lumps (destroy previous ones)
SetLumpData( );
if ( s_nDetailOverflow != 0 )
{
Warning( "Error! Too many detail props on this map. %d were not emitted!\n", s_nDetailOverflow );
}
}
示例12: IpSecCryptoIoGenerateRandomBytes
/**
Generates random numbers of specified size.
If the Random Generator wasn't initiated, initiate it first, then call RandomBytes.
@param[out] OutBuffer Pointer to buffer to receive random value.
@param[in] Bytes Size of randome bytes to generate.
@retval EFI_SUCCESS The operation perfoms successfully.
@retval Otherwise The operation is failed.
**/
EFI_STATUS
IpSecCryptoIoGenerateRandomBytes (
OUT UINT8* OutBuffer,
IN UINTN Bytes
)
{
if (!mInitialRandomSeed) {
RandomSeed (NULL, 0);
mInitialRandomSeed = TRUE;
}
if (RandomBytes (OutBuffer, Bytes)) {
return EFI_SUCCESS;
} else {
return EFI_INVALID_PARAMETER;
}
}
示例13: CryptoInitialize
void CryptoInitialize()
{
if (!crypto_initialized)
{
SetupOpenSSLThreadLocks();
OpenSSL_add_all_algorithms();
OpenSSL_add_all_digests();
ERR_load_crypto_strings();
RandomSeed();
long seed = 0;
RAND_bytes((unsigned char *)&seed, sizeof(seed));
srand48(seed);
crypto_initialized = true;
}
}
示例14: ToBasePlayer
//-----------------------------------------------------------------------------
// Purpose: Calculate the viewkick
//-----------------------------------------------------------------------------
void CWeaponAK47::AddViewKick( void )
{
CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
if ( pPlayer == NULL )
{ return; }
int iSeed = CBaseEntity::GetPredictionRandomSeed() & 255;
RandomSeed( iSeed );
QAngle viewPunch;
viewPunch.x = random->RandomFloat( 0.25f, 0.5f );
viewPunch.y = random->RandomFloat( -.6f, .6f );
viewPunch.z = 0.0f;
//Add it to the view punch
pPlayer->ViewPunch( viewPunch );
}
示例15: CryptoInitialize
void CryptoInitialize()
{
static bool crypto_initialized = false;
if (!crypto_initialized)
{
OpenSSL_add_all_algorithms();
OpenSSL_add_all_digests();
ERR_load_crypto_strings();
RandomSeed();
long seed = 0;
RAND_bytes((unsigned char *)&seed, sizeof(seed));
srand48(seed);
crypto_initialized = true;
}
}