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

C++ RandomSeed函数代码示例

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

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



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


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

}
开发者ID:burnmg,项目名称:vfml,代码行数:48,代码来源:vfbn2.c


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


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


示例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); 
}
开发者ID:DINKIN,项目名称:booksim2,代码行数:27,代码来源:traffic.cpp


示例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 );
}
开发者ID:P1x3lF3v3r,项目名称:Estranged-Act-1,代码行数:8,代码来源:util_shared.cpp


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


示例8: CryptoInitialize

void CryptoInitialize()
{
    if (!crypto_initialized)
    {
        SetupOpenSSLThreadLocks();
        OpenSSL_add_all_algorithms();
        OpenSSL_add_all_digests();
        ERR_load_crypto_strings();

        RandomSeed();

        crypto_initialized = true;
    }
}
开发者ID:markburgess,项目名称:Cellibrium,代码行数:14,代码来源:crypto.c


示例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;
}
开发者ID:P1x3lF3v3r,项目名称:Estranged-Act-1,代码行数:14,代码来源:util_shared.cpp


示例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();
    }
开发者ID:KermitAudio,项目名称:MSS,代码行数:48,代码来源:serverbenchmark_base.cpp


示例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 );
	}
}
开发者ID:RaisingTheDerp,项目名称:raisingthebar,代码行数:19,代码来源:detailobjects.cpp


示例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;
  }
}
开发者ID:jeppeter,项目名称:vbox,代码行数:28,代码来源:IpSecCryptIo.c


示例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;
    }
}
开发者ID:patuchov,项目名称:core,代码行数:18,代码来源:crypto.c


示例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 );
}
开发者ID:js564,项目名称:final,代码行数:21,代码来源:weapon_ak47.cpp


示例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;
    }
}
开发者ID:jeffali,项目名称:core,代码行数:19,代码来源:crypto.c


示例16: md5_random

void nospread::ApplySpread(int sequence_number, Entity *pl, Angle &angles, float factor)
{
	Entity *w = pl->GetActiveWeapon();

	int random_seed = md5_random(sequence_number) & 0x7fffffff;

#if defined(CSS) || defined(CSGO)
	RandomSeed(random_seed + 1 & 0xff);

	w->UpdateAccuracyPenalty();

	float random1 = RandomFloat(0.0f, pi * 2.0f);
	float spread1 = RandomFloat(0.0f, w->GetWeaponCone());
	float random2 = RandomFloat(0.0f, pi * 2.0f);
	float spread2 = RandomFloat(0.0f, w->GetWeaponSpread());

	float sin1, cos1, sin2, cos2;
	SinCos(random1, sin1, cos1);
	SinCos(random2, sin2, cos2);

	Vector spread = Vector(1.0f, (cos1 * spread1 + cos2 * spread2) * -factor, (sin1 * spread1 + sin2 * spread2) * factor);
	spread.Normalize();

	Angle shake;
	VectorAngles(spread, shake);

	angles += shake;
#endif

#if defined(L4D) || defined(L4D2)
	static auto SharedRandomFloat = (float (*)(const char *, float, float, int))util::FindProlog(util::FindString(GetModuleHandle("client"), "SharedRandomFloat"));
	static int &r_random_seed = **(int **)util::FindPattern((void *)SharedRandomFloat, 0x100, ((const pattern *)"\x01\x01\x00\x00\x00\xA1"));

 	r_random_seed = random_seed;

	float spread = w->GetWeaponSpread();

	angles.x += SharedRandomFloat("CTerrorGun::FireBullet HorizSpread", -spread, spread, 0) * factor;
	angles.y += SharedRandomFloat("CTerrorGun::FireBullet VertSpread",  -spread, spread, 0) * factor;
#endif
}
开发者ID:TSM-Dev,项目名称:nh30,代码行数:41,代码来源:nospread.cpp


示例17: CryptoInitialize

void CryptoInitialize()
{
    static bool crypto_initialized = false;

    if (!crypto_initialized)
    {
        OpenSSL_add_all_algorithms();
        OpenSSL_add_all_digests();
        ERR_load_crypto_strings();

        RandomSeed();
        unsigned char s[16] = { 0 };
        int seed = 0;
        RAND_bytes(s, 16);
        s[15] = '\0';
        seed = ElfHash(s, CF_HASHTABLESIZE);
        srand48((long) seed);

        crypto_initialized = true;
    }
}
开发者ID:chrishiestand,项目名称:core,代码行数:21,代码来源:crypto.c


示例18: RandomSeed

void CGEPropDynamic::PickNewSkin(bool broken)
{
	// Basically a way of making sure each entity gets a unique skin.
	// We multiply the different coordinates with different coefficients in order to prevent certain arrangements from generating the same seed.
	// aka (-2, 0, 0) is the same as (-1, -1, 0) and many more.  Overlap is obviously still possible with this system too, but there are only a few
	// circumstances where the overlap would occour in locations near eachother.
	RandomSeed((int)(GetAbsOrigin().x * 100 + GetAbsOrigin().y * 10 + GetAbsOrigin().z) + GEMPRules()->GetRandomSeedOffset() + gpGlobals->curtime);

	int healthyskins = GetModelPtr()->numskinfamilies() - m_iBrokenSkinCount;

	if (broken)
	{
		m_nSkin = rand() % m_iBrokenSkinCount;
		m_bUsingBrokenSkin = true;
	}
	else
	{
		m_nSkin = m_iBrokenSkinCount + rand() % healthyskins;
		m_bUsingBrokenSkin = false;
	}
}
开发者ID:djoslin0,项目名称:ges-legacy-code,代码行数:21,代码来源:prop_ge_dynamic.cpp


示例19: RandomSeed

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CHL2MPMachineGun::DoMachineGunKick( CBasePlayer *pPlayer, float dampEasy, float maxVerticleKickAngle, float fireDurationTime, float slideLimitTime )
{
	#define	KICK_MIN_X			0.2f	//Degrees
	#define	KICK_MIN_Y			0.2f	//Degrees
	#define	KICK_MIN_Z			0.1f	//Degrees

	QAngle vecScratch;
	int iSeed = CBaseEntity::GetPredictionRandomSeed() & 255;
	
	//Find how far into our accuracy degradation we are
	float duration	= ( fireDurationTime > slideLimitTime ) ? slideLimitTime : fireDurationTime;
	float kickPerc = duration / slideLimitTime;

	// do this to get a hard discontinuity, clear out anything under 10 degrees punch
	pPlayer->ViewPunchReset( 10 );

	//Apply this to the view angles as well
	vecScratch.x = -( KICK_MIN_X + ( maxVerticleKickAngle * kickPerc ) );
	vecScratch.y = -( KICK_MIN_Y + ( maxVerticleKickAngle * kickPerc ) ) / 3;
	vecScratch.z = KICK_MIN_Z + ( maxVerticleKickAngle * kickPerc ) / 8;

	RandomSeed( iSeed );

	//Wibble left and right
	if ( RandomInt( -1, 1 ) >= 0 )
		vecScratch.y *= -1;

	iSeed++;

	//Wobble up and down
	if ( RandomInt( -1, 1 ) >= 0 )
		vecScratch.z *= -1;

	//Clip this to our desired min/max
	UTIL_ClipPunchAngleOffset( vecScratch, pPlayer->m_Local.m_vecPunchAngle, QAngle( 24.0f, 3.0f, 1.0f ) );

	//Add it to the view punch
	// NOTE: 0.5 is just tuned to match the old effect before the punch became simulated
	pPlayer->ViewPunch( vecScratch * 0.5 );
}
开发者ID:SizzlingStats,项目名称:hl2sdk-ob-valve,代码行数:43,代码来源:weapon_hl2mpbase_machinegun.cpp


示例20: RandomSeed

void SgObjectManager::Update( SgMap *map , SgViewPort *viewport , SgInputManager* pInput )
{
	//if the game is paused we just draw the objects (and don't animate them)
	if(m_pTimer->IsPaused())
	{
		return;
	}
	//Create a new random seed for randomness.
	RandomSeed(timeGetTime());
	//animate each object individually (if user object we pass the input along)
	for(int i=0; i<m_dwMaxObjects; i++){
		//if object exists
		if(m_ppObject[i]!=NULL){
			if(i!=(m_dwUserObject-1)){
				m_ppObject[i]->Animate(m_pTimer, map, NULL, this);
			}else{
				m_ppObject[i]->Animate(m_pTimer, map, pInput, this);
			}
		}
	}

	//set the viewport to the user objects
	viewport->update(m_pTimer->Time());

	if((m_dwUserObject>0) && (m_ppObject[m_dwUserObject-1]!=NULL) )
	{
		viewport->force_position(m_ppObject[m_dwUserObject-1]->GetX(), m_ppObject[m_dwUserObject-1]->GetY());
		
	}
	else
	{
		viewport->stop_scroll();
	}

	//detect collisions (which will do all necessary steps if there is a collision)
	DetectCollisions();
	
	Cull(); //cull old objects
}
开发者ID:beemfx,项目名称:ScrollGIN,代码行数:39,代码来源:ObjMan.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ RandomUInt函数代码示例发布时间:2022-05-30
下一篇:
C++ RandomPermute函数代码示例发布时间: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