示例#1
0
long RandomLong( long lLow, long lHigh )
{
	if (idum == 0)
	{
		SeedRandomNumberGenerator(0);
	}

	unsigned long maxAcceptable;
	unsigned long x = lHigh-lLow+1;
	unsigned long n;
	if (x <= 0 || MAX_RANDOM_RANGE < x-1)
	{
		return lLow;
	}

	// The following maps a uniform distribution on the interval [0,MAX_RANDOM_RANGE]
	// to a smaller, client-specified range of [0,x-1] in a way that doesn't bias
	// the uniform distribution unfavorably. Even for a worst case x, the loop is
	// guaranteed to be taken no more than half the time, so for that worst case x,
	// the average number of times through the loop is 2. For cases where x is
	// much smaller than MAX_RANDOM_RANGE, the average number of times through the
	// loop is very close to 1.
	//
	maxAcceptable = MAX_RANDOM_RANGE - ((MAX_RANDOM_RANGE+1) % x );
	do
	{
		n = ran1();
	} while (n > maxAcceptable);

	return lLow + (n % x);
}
示例#2
0
int Sys_InitGame() {

   //Four args, three unused, and one I don't care to use.
   //char * gamedir[0x100];



   //gmodinfo might need zeroing out on server restarts and whatnot, but for the
   //first server, there ought to be no troubles.

   //Tracing sucks.
   SeedRandomNumberGenerator();

   Sys_InitMemory();

   if(Host_Init(&host_parms) == 0) { //failed.
      return(0);
   }

   Sys_Init(); //be after host_init, as cvars need memory.

   //COM_GetGameDirSize(gamedir, sizeof(gamedir));
   //Sys_InitAuthentication

   Host_InitializeGameDLL();
   Banlist_Init();
   NET_Config(1);

   return(1);
}
示例#3
0
float Lapidem_Math::RandomFloat( float flLow, float flHigh )
{
	if( idum == 0 )
		SeedRandomNumberGenerator( 0 );

	float fl = fran1( );
	return ( fl * ( flHigh - flLow ) ) + flLow;
}
示例#4
0
bool CFidgetApp::Initialize(HINSTANCE hInstance, int nCmdShow)
{
    m_hInstance = hInstance;

    TIME_Initialize();
    init_timer();
    SeedRandomNumberGenerator();

    if (!EnableHook())
    {
        return false;
    }

    m_hRichEdit = ::LoadLibrary(L"Msftedit.dll");
    if (NULL != m_hRichEdit)
    {
        m_bMsftEdit = true;
    }
    else
    {
        m_hRichEdit = ::LoadLibrary(L"Riched20.dll");
        if (NULL != m_hRichEdit)
        {
            m_bMsftEdit = false;
        }
        else
        {
            return false;
        }
    }

    m_pMainFrame = new (std::nothrow) CMainFrame;

    if (  NULL == m_pMainFrame
       || !RegisterClasses())
    {
        return false;
    }

    int xSize = ::GetSystemMetrics(SM_CXSCREEN);
    int ySize = ::GetSystemMetrics(SM_CYSCREEN);
    int cx = (9*xSize)/10;
    int cy = (9*ySize)/10;
    int x = (xSize - cx)/2;
    int y = (ySize - cy)/2;

    if (!m_pMainFrame->Create(x, y, cx, cy))
    {
        UnregisterClasses();
        return false;
    }

    m_pMainFrame->ShowWindow(nCmdShow);
    m_pMainFrame->UpdateWindow();

    return true;
}
示例#5
0
float Com_RandomFloat( float flLow, float flHigh )
{
	float	fl;

	if( idum == 0 ) SeedRandomNumberGenerator(0);

	fl = fran1(); // float in [0, 1)
	return (fl * (flHigh - flLow)) + flLow; // float in [low, high)
}
示例#6
0
long Lapidem_Math::RandomLong( long lLow, long lHigh )
{
	if( idum == 0 )
		SeedRandomNumberGenerator( 0 );

	ul32 maxAcceptable;
	ul32 x = lHigh - lLow + 1;
	ul32 n;

	if( x <= 0 || MAX_RAND_RANGE < x - 1 )
		return lLow;

	maxAcceptable = MAX_RAND_RANGE - ( ( MAX_RAND_RANGE + 1 ) % x );

	do { n = ran1( ); }
	while ( n > maxAcceptable );

	return lLow + ( n% x );
}