void StateMenu::GenerateNumbers() {
    unsigned int total_numb = (m_HexaColCount*m_HexaRowCount)/2 + 5;
    std::vector<int> numberPA;
    std::vector<int> numberPB;
    // generate
    for(int j=0; j<total_numb; j++) {
        unsigned int numbvalue = ( j % 12) + 1;
        m_Player_A.Numbers.push_back( numbvalue );
        m_Player_B.Numbers.push_back( numbvalue );
    }
    // assign
    for(unsigned int a=0; a<1000; a++) {
        for(unsigned int k=0; k<total_numb; k++) {
            // A
            int b = RandomRange(0,total_numb);
            int temp = m_Player_A.Numbers[ b ];
            m_Player_A.Numbers[ b ] = m_Player_A.Numbers[ k ];
            m_Player_A.Numbers[ k ] = temp;
            // B
            int c = RandomRange(0,total_numb);
            int temp2 = m_Player_B.Numbers[ c ];
            m_Player_B.Numbers[ c ] = m_Player_B.Numbers[ k ];
            m_Player_B.Numbers[ k ] = temp2;
        }
    }
#if 1
    for(int j=0; j<total_numb; j++) {
        std::cout<<" Number ["<<j<<"]:  "<< m_Player_A.Numbers[j] <<" --  "<< m_Player_B.Numbers[j] <<std::endl;
    }
#endif
}
Пример #2
0
luna::Function * RandomFunction()
{
    auto f = g_gc.NewFunction();

    auto s = RandomString();
    f->SetModuleName(s);
    f->SetLine(RandomNum(1000));

    int instruction_count = RandomRange(10, 1000);
    for (int i = 0; i < instruction_count; ++i)
    {
        unsigned int op_min = luna::OpType_LoadNil;
        unsigned int op_max = luna::OpType_GetGlobal;
        luna::OpType op = static_cast<luna::OpType>(RandomRange(op_min, op_max));
        luna::Instruction instruction(op, RandomNum(128), RandomNum(128), RandomNum(128));
        f->AddInstruction(instruction, i);
    }

    int const_num = RandomNum(5);
    for (int i = 0; i < const_num; ++i)
        f->AddConstNumber(RandomNum(100000));

    int const_str = RandomNum(5);
    for (int i = 0; i < const_str; ++i)
        f->AddConstString(RandomString());

    CHECK_BARRIER(g_gc, f);

    return f;
}
Пример #3
0
SSNGenerator(char* param_name, char* ssnNoSpace)
{
    int randSSN[3];
    char EmployeeDep1SSN[100];
    char EmployeeDep1SSN_1[100];
    char p_SSN_1[100];

    randSSN[0] = RandomRange(100,999);
    randSSN[1] = RandomRange(10,99);
    randSSN[2] = RandomRange(1000,9999);

    lr_save_int(randSSN[0],"pSSN1dep1_1");
    lr_save_int(randSSN[1],"pSSN2dep1_1");
    lr_save_int(randSSN[2],"pSSN3dep1_1");

    sprintf(EmployeeDep1SSN, "%s-%s-%s", lr_eval_string("{pSSN1dep1_1}"), lr_eval_string("{pSSN2dep1_1}"), lr_eval_string("{pSSN3dep1_1}"));
    sprintf(EmployeeDep1SSN_1, "%s%s%s", lr_eval_string("{pSSN1dep1_1}"), lr_eval_string("{pSSN2dep1_1}"), lr_eval_string("{pSSN3dep1_1}"));

    lr_save_string(EmployeeDep1SSN, "EmployeeDep1SSN");

    lr_save_string(EmployeeDep1SSN, param_name);
    lr_save_string(EmployeeDep1SSN_1, ssnNoSpace);

    return 0;
}
Пример #4
0
void RandomLoop()
{
    int free_global_count_max = 20;

    while (true)
    {
        g_scopeClosure.clear();
        g_scopeString.clear();
        g_scopeTable.clear();

        int scope_count = RandomRange(1, 1000);
        RunScope(scope_count);

        TouchGlobalTable(RandomNum(scope_count));

        int free_count = RandomRange(1, free_global_count_max++);
        FreeGlobal(free_count);

        if (free_global_count_max >= 1000)
            free_global_count_max = 20;

        g_gc.CheckGC();
#ifdef _MSC_VER
        Sleep(RandomRange(1, 20));
#else
        usleep(RandomRange(1000, 20000));
#endif // _MSC_VER
    }
}
Пример #5
0
luna::String * RandomString()
{
    std::string str;
    int count = RandomRange(1, 150);
    for (int i = 0; i < count; ++i)
        str.push_back(RandomRange('a', 'z'));

    auto s = g_gc.NewString();
    s->SetValue(str);
    return s;
}
Пример #6
0
luna::Value RandomValue(bool exclude_table)
{
    luna::ValueT type = luna::ValueT_Nil;
    int percent = RandomRange(1, 100);
    if (percent <= 20)
        type = luna::ValueT_Nil;
    else if (percent <= 30)
        type = luna::ValueT_Bool;
    else if (percent <= 60)
        type = luna::ValueT_Number;
    else if (percent <= 70)
        type = luna::ValueT_String;
    else if (percent <= 80)
        type = luna::ValueT_Closure;
    else if (percent <= 90)
        type = luna::ValueT_CFunction;
    else
        type = exclude_table ? luna::ValueT_Number : luna::ValueT_Table;

    luna::Value value;
    value.type_ = type;
    switch (type)
    {
        case luna::ValueT_Nil:
            break;
        case luna::ValueT_Bool:
            value.bvalue_ = RandomRange(0, 1) ? true : false;
            break;
        case luna::ValueT_Number:
            value.num_ = RandomNum(100000);
            break;
        case luna::ValueT_Obj:
            value.obj_ = RandomString();
            break;
        case luna::ValueT_String:
            value.str_ = RandomString();
            break;
        case luna::ValueT_Closure:
            value.closure_ = RandomClosure();
            break;
        case luna::ValueT_Table:
            value.table_ = RandomTable();
            break;
        case luna::ValueT_CFunction:
            break;
        default:
            break;
    }

    return value;
}
Пример #7
0
inline T RandomNum(T max)
{
    if (max == 0)
        return 0;
    else
        return RandomRange(static_cast<T>(0), max - 1);
}
Пример #8
0
/** Perform the monthly update of open subsidies, and try to create a new one. */
void SubsidyMonthlyLoop()
{
	bool modified = false;

	Subsidy *s;
	FOR_ALL_SUBSIDIES(s) {
		if (--s->remaining == 0) {
			if (!s->IsAwarded()) {
				Pair reftype = SetupSubsidyDecodeParam(s, true);
				AddNewsItem(STR_NEWS_OFFER_OF_SUBSIDY_EXPIRED, NT_SUBSIDIES, NF_NORMAL, (NewsReferenceType)reftype.a, s->src, (NewsReferenceType)reftype.b, s->dst);
				AI::BroadcastNewEvent(new ScriptEventSubsidyOfferExpired(s->index));
				Game::NewEvent(new ScriptEventSubsidyOfferExpired(s->index));
			} else {
				if (s->awarded == _local_company) {
					Pair reftype = SetupSubsidyDecodeParam(s, true);
					AddNewsItem(STR_NEWS_SUBSIDY_WITHDRAWN_SERVICE, NT_SUBSIDIES, NF_NORMAL, (NewsReferenceType)reftype.a, s->src, (NewsReferenceType)reftype.b, s->dst);
				}
				AI::BroadcastNewEvent(new ScriptEventSubsidyExpired(s->index));
				Game::NewEvent(new ScriptEventSubsidyExpired(s->index));
			}
			delete s;
			modified = true;
		}
	}

	if (modified) RebuildSubsidisedSourceAndDestinationCache();

	bool passenger_subsidy = false;
	bool town_subsidy = false;
	bool industry_subsidy = false;

	int random_chance = RandomRange(16);

	if (random_chance < 2) {
		/* There is a 1/8 chance each month of generating a passenger subsidy. */
		int n = 1000;

		do {
			passenger_subsidy = FindSubsidyPassengerRoute();
		} while (!passenger_subsidy && n--);
	} else if (random_chance == 2) {
		/* Cargo subsidies with a town as a source have a 1/16 chance. */
		int n = 1000;

		do {
			town_subsidy = FindSubsidyTownCargoRoute();
		} while (!town_subsidy && n--);
	} else if (random_chance == 3) {
		/* Cargo subsidies with an industry as a source have a 1/16 chance. */
		int n = 1000;

		do {
			industry_subsidy = FindSubsidyIndustryCargoRoute();
		} while (!industry_subsidy && n--);
	}

	modified |= passenger_subsidy || town_subsidy || industry_subsidy;

	if (modified) InvalidateWindowData(WC_SUBSIDIES_LIST, 0);
}
Пример #9
0
/**
 * Tries to create a cargo subsidy with a town as source.
 * @return True iff the subsidy was created.
 */
bool FindSubsidyTownCargoRoute()
{
	if (!Subsidy::CanAllocateItem()) return false;

	SourceType src_type = ST_TOWN;

	/* Select a random town. */
	const Town *src_town = Town::GetRandom();

	uint32 town_cargo_produced = src_town->cargo_produced;

	/* Passenger subsidies are not handled here. */
	ClrBit(town_cargo_produced, CT_PASSENGERS);

	/* No cargo produced at all? */
	if (town_cargo_produced == 0) return false;

	/* Choose a random cargo that is produced in the town. */
	uint8 cargo_number = RandomRange(CountBits(town_cargo_produced));
	CargoID cid;
	FOR_EACH_SET_CARGO_ID(cid, town_cargo_produced) {
		if (cargo_number == 0) break;
		cargo_number--;
	}

	/* Avoid using invalid NewGRF cargoes. */
	if (!CargoSpec::Get(cid)->IsValid()) return false;

	/* Quit if the percentage transported is large enough. */
	if (src_town->GetPercentTransported(cid) > SUBSIDY_MAX_PCT_TRANSPORTED) return false;

	SourceID src = src_town->index;

	return FindSubsidyCargoDestination(cid, src_type, src);
}
Пример #10
0
ParticleType::ParticleType( ParticleType *pNext )
{
	m_pSprayType = m_pOverlayType = NULL;
	m_StartAngle = RandomRange(45);
	m_hSprite = 0;
	m_pNext = pNext;
	m_szName[0] = 0;
	m_StartRed = m_StartGreen = m_StartBlue = m_StartAlpha = RandomRange(1);
	m_EndRed = m_EndGreen = m_EndBlue = m_EndAlpha = RandomRange(1);
	m_iRenderMode = kRenderTransAdd;
	m_iDrawCond = 0;
	m_bEndFrame = false;

	m_bIsDefined = false;
	m_iCollision = 0;
}
Пример #11
0
// GetSquareAverage                                                  //
// Gets NESW neighbours (if within bounds) and returns average value //
float TerrainClass::GetSquareAverage( std::vector< float > &vector, int i, int j, int step, float randomRange, float smoothingValue ) {
	// Initialize variables
	float averageHeight = 0.0f;
	float numOfAverages = 0;

	// North
	if( ( j - step ) >= 0 ) {
		averageHeight += vector[ ( mTerrainHeight * ( j - step ) ) + i ];
		numOfAverages++;
	}
	// East
	if( ( i + step ) < ( mTerrainWidth ) ) {
		averageHeight += vector[ ( mTerrainHeight * j ) + ( i + step ) ];
		numOfAverages++;
	}
	// South
	if( ( j + step ) < ( mTerrainHeight ) ) {
		averageHeight += vector[ ( mTerrainHeight * ( j + step ) ) + i ];
		numOfAverages++;
	}
	// West
	if( ( i - step ) >= 0 ) {
		averageHeight += vector[ ( mTerrainHeight * j ) + ( i - step ) ];
		numOfAverages++;
	}

	// Calculate square average plus small random offset
	float newHeight = ( averageHeight / numOfAverages ) + RandomRange( -randomRange, randomRange ) / smoothingValue; 

	// Return newHeight
	return newHeight;
}
Пример #12
0
AIInfo *AIScannerInfo::SelectRandomAI() const
{
	uint num_random_ais = 0;
	for (ScriptInfoList::const_iterator it = this->info_single_list.begin(); it != this->info_single_list.end(); it++) {
		AIInfo *i = static_cast<AIInfo *>((*it).second);
		if (i->UseAsRandomAI()) num_random_ais++;
	}

	if (num_random_ais == 0) {
		DEBUG(script, 0, "No suitable AI found, loading 'dummy' AI.");
		return this->info_dummy;
	}

	/* Find a random AI */
	uint pos;
	if (_networking) {
		pos = InteractiveRandomRange(num_random_ais);
	} else {
		pos = RandomRange(num_random_ais);
	}

	/* Find the Nth item from the array */
	ScriptInfoList::const_iterator it = this->info_single_list.begin();

#define GetAIInfo(it) static_cast<AIInfo *>((*it).second)
	while (!GetAIInfo(it)->UseAsRandomAI()) it++;
	for (; pos > 0; pos--) {
		it++;
		while (!GetAIInfo(it)->UseAsRandomAI()) it++;
	}
	return GetAIInfo(it);
#undef GetAIInfo
}
Пример #13
0
extern "C" _declspec(dllexport) void __cdecl HumanMMouse( int eX, int eY)
{
    int A = MouseSpeed;
    int x = 0; int y = 0;
    GetMousePosition(x,y);
    int Dist = Distance(x,y,eX,eY);
    int MP = rnd(Dist/100);
     if (MP < 0)
       MP =1;
    float randSpeed = ((rand()%MouseSpeed) / 2.0 + MouseSpeed) / 10.0;
    WindMouse(x, y, RandomRange(eX-(A*MP), eX+(A*MP)), RandomRange(eY-(A*MP), eY+(A*MP)),
            30, 55, 10.0 / randSpeed, 12.0 / randSpeed, 10.0 * randSpeed, 10.0 * randSpeed);
    GetMousePosition(x, y);
    WindMouse(x, y, eX, eY, 30, 55, 10.0 / randSpeed, 12.0 / randSpeed, 10.0 * randSpeed, 10.0 * randSpeed);

    MouseSpeed = A;
}
Пример #14
0
/*
===============
hhSound::DetermineVolume
===============
*/
bool hhSound::DetermineVolume( float& volume ) {
	if( !spawnArgs.GetBool("s_useRandomVolume") ) {
		return false;
	}

	volume = hhMath::dB2Scale( RandomRange(spawnArgs.GetInt("s_minVolume"), spawnArgs.GetInt("s_maxVolume")) );
	return true;
}
Пример #15
0
	FOR_LOC(x, y, loc)
    {
        if (loc.Void())
            continue;

		if (RandomPerc(90))
			continue;

		short z = the_world->Loc(x, y).ceil_h*4 - 2;

		lev_ents.push_back(new entity_c(VX(x,2), VY(y,2), z, ENT_LIGHT));

		entity_c *E = lev_ents[lev_ents.size()-1];

		E->attrs[0] = RandomRange(4,16);
		E->attrs[1] = RandomRange(25,255);
    }}
Пример #16
0
/*
===============
hhSound::DeterminePositionOffset
===============
*/
idVec3 hhSound::DeterminePositionOffset() {
	if( !spawnArgs.GetBool("s_useRandomPosition") ) {
		return vec3_origin;
	}

	float radius = RandomRange( spawnArgs.GetFloat("s_minRadius"), spawnArgs.GetFloat("s_maxRadius") );
	return hhUtils::RandomVector() * radius;
}
Пример #17
0
CParticleType :: CParticleType( CParticleType *pNext )
{
	m_pSprayType = m_pOverlayType = NULL;
	m_StartAngle = RandomRange( 45.0f );
	m_pNext = pNext;
	m_szName[0] = 0;
	m_hSprite = 0;

	m_StartRed = m_StartGreen = m_StartBlue = m_StartAlpha = RandomRange( 1.0f );
	m_EndRed = m_EndGreen = m_EndBlue = m_EndAlpha = RandomRange( 1.0f );

	m_iRenderMode = kRenderTransAdd;
	m_iDrawCond = CONTENTS_NONE;
	m_bIsDefined = false;
	m_bEndFrame = false;
	m_bBouncing = false;
}
Пример #18
0
extern "C" _declspec(dllexport) void __cdecl FastClick( TClickType button )
{
  int x = 0, y = 0;
  GetMousePosition( x, y );
  HoldMouse( x, y, button );
  Sleep( RandomRange( 60, 150 ) );
  GetMousePosition( x, y );
  ReleaseMouse( x, y, button );
}
Пример #19
0
Point3D LineSegment::GetRandomPoint() const
{
	if (p1.GetX() == p2.GetX())
	{
		Float y = RandomRange(p1.GetY(), p2.GetY());

		return Point3D(p1.GetX(), y, 0);
	}
	else
	{
		Float dx = RandomRange(0, p2.GetX() - p1.GetX());
		Float dy = GetSlope() * dx;

		return Point3D(p1.GetX() + dx,
					   p1.GetY() + dy,
					   0);
	}
}
Пример #20
0
extern "C" _declspec(dllexport) void __cdecl MissMouse( int eX, int eY, int ranx, int rany )
{
  float randSpeed = 0.0;
  int x = 0, y = 0, x2 = 0, y2 = 0, a = 0, dist = 0, MP = 0;
  a = MouseSpeed;
  GetMousePosition( x, y );
  dist = Distance( x, y, eX, eY );
  MP = rnd(  dist  / 150 );
  if ( MP < 0 )
    MP = 1;
  randSpeed = (  rand()% MouseSpeed / 2.0 + MouseSpeed ) / 10.0;
  x2 = RandomRange( eX - ( a * MP ), eX + ( a * MP ) );
  y2 = RandomRange( eY - ( a * MP ), eY + ( a * MP ) );
  ShiftWindMouse( x, y, x2, y2, 11, 8, 10.0 / randSpeed, 12.0 / randSpeed, 10.0 * randSpeed, 10.0 * randSpeed );
  GetMousePosition( x, y );
  MMouse( eX, eY, ranx, rany );
  MouseSpeed = a;
}
void Button::Render()	{
    //m_Anim->Render();
    if( m_HoverState ) {
        debugSystemPtr->Renderer->DrawRect( XMFLOAT2(m_PosX-4,m_PosY-4),XMFLOAT2(m_Width+8,m_Height+8) );
    } else {
        debugSystemPtr->Renderer->DrawRect( XMFLOAT2(m_PosX,m_PosY),XMFLOAT2(m_Width,m_Height) );
    }
    if(m_ClickedState>0 && m_ClickedState < 20) {
        int r_v = RandomRange(2,20);
        debugSystemPtr->Renderer->DrawRect( XMFLOAT2(m_PosX-r_v,m_PosY-r_v),XMFLOAT2(m_Width+2*r_v,m_Height+2*r_v) );
        m_ClickedState++;
    }
}
Пример #22
0
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);

}
Пример #23
0
Geometry BubbleEmitter::CreateGeometry( unsigned int numOfPatch )
{
  unsigned int numVertex = numOfPatch*4u;
  std::vector<Vertex> vertexData;
  vertexData.reserve( numVertex );

  unsigned int numIndex = numOfPatch*6u;
  Vector<unsigned int> indexData;
  indexData.Reserve( numIndex );

  for(unsigned int i = 0; i < numOfPatch; i++)
  {
    float curSize = RandomRange(mBubbleSizeRange.x, mBubbleSizeRange.y, mRandomSeed);

    float index = static_cast<float>( i );
    vertexData.push_back( Vertex( index, Vector2(0.f,0.f),         Vector2(0.f,0.f) ) );
    vertexData.push_back( Vertex( index, Vector2(0.f,curSize),     Vector2(0.f,1.f)  ) );
    vertexData.push_back( Vertex( index, Vector2(curSize,curSize), Vector2(1.f,1.f)  ) );
    vertexData.push_back( Vertex( index, Vector2(curSize,0.f),     Vector2(1.f,0.f)  ) );

    unsigned int idx = index * 4;
    indexData.PushBack( idx );
    indexData.PushBack( idx+1 );
    indexData.PushBack( idx+2 );
    indexData.PushBack( idx );
    indexData.PushBack( idx+2 );
    indexData.PushBack( idx+3 );
  }

  Property::Map vertexFormat;
  vertexFormat["aIndex"] = Property::FLOAT;
  vertexFormat["aPosition"] = Property::VECTOR2;
  vertexFormat["aTexCoord"] = Property::VECTOR2;
  PropertyBuffer vertices = PropertyBuffer::New( vertexFormat, numVertex  );
  vertices.SetData( &vertexData[0] );

  Property::Map indexFormat;
  indexFormat["indices"] = Property::INTEGER;
  PropertyBuffer indices = PropertyBuffer::New( indexFormat, numIndex  );
  indices.SetData( &indexData[0] );

  Geometry geometry = Geometry::New();
  geometry.AddVertexBuffer( vertices );
  geometry.SetIndexBuffer( indices );

  return geometry;
}
Пример #24
0
/**
 * Truncates where each destination loses roughly the same percentage of its
 * cargo. This is done by randomizing the selection of packets to be removed.
 * Optionally count the cargo by origin station.
 * @param max_move Maximum amount of cargo to remove.
 * @param cargo_per_source Container for counting the cargo by origin.
 * @return Amount of cargo actually moved.
 */
uint StationCargoList::Truncate(uint max_move, StationCargoAmountMap *cargo_per_source)
{
	max_move = min(max_move, this->count);
	uint prev_count = this->count;
	uint moved = 0;
	uint loop = 0;
	bool do_count = cargo_per_source != NULL;
	while (max_move > moved) {
		for (Iterator it(this->packets.begin()); it != this->packets.end();) {
			CargoPacket *cp = *it;
			if (prev_count > max_move && RandomRange(prev_count) < prev_count - max_move) {
				if (do_count && loop == 0) {
					(*cargo_per_source)[cp->source] += cp->count;
				}
				++it;
				continue;
			}
			uint diff = max_move - moved;
			if (cp->count > diff) {
				if (diff > 0) {
					this->RemoveFromCache(cp, diff);
					cp->Reduce(diff);
					moved += diff;
				}
				if (loop > 0) {
					if (do_count) (*cargo_per_source)[cp->source] -= diff;
					return moved;
				} else {
					if (do_count) (*cargo_per_source)[cp->source] += cp->count;
					++it;
				}
			} else {
				it = this->packets.erase(it);
				if (do_count && loop > 0) {
					(*cargo_per_source)[cp->source] -= cp->count;
				}
				moved += cp->count;
				this->RemoveFromCache(cp, cp->count);
				delete cp;
			}
		}
		loop++;
	}
	return moved;
}
Пример #25
0
void CTestRangeMap::TestRangeMap(void) const
{
    Filling("CRangeMap");

    typedef CRangeMultimap<CConstRef<CObject> > TMap;
    typedef TMap::const_iterator TMapCI;

    TMap m;

    // fill
    for ( int count = 0; count < m_RangeNumber; ) {
        TRange range = RandomRange();
        m.insert(TMap::value_type(range, CConstRef<CObject>(0)));
        ++count;
        Added(range);
    }
    
    if ( m_PrintSize ) {
        Filled(m.size());
        // Stat(m.stat());
    }

    for ( TMapCI i = m.begin(); i; ++i ) {
        FromAll(i.GetInterval());
    }

    size_t scannedCount = 0;
    for ( int count = 0; count < m_ScanCount; ++count ) {
        for ( int pos = 0; pos <= m_Length + 2*m_RangeLength;
              pos += m_ScanStep ) {
            TRange range;
            range.Set(pos, pos + m_ScanLength - 1);
            
            StartFrom(range);
            
            for ( TMapCI i = m.begin(range); i; ++i ) {
                From(range, i.GetInterval());
                ++scannedCount;
            }
        }
    }
    PrintTotalScannedNumber(scannedCount);

    End();
}
Пример #26
0
JewelType Bejeweled::GetRandomJewel() {
	float random = RandomRange(0,7);
	if(random < 1) {
		return jtRed;
	} else if(random < 2) {
		return jtGreen;
	} else if(random < 3) {
		return jtBlue;
	} else if(random < 4) {
		return jtYellow;
	} else if(random < 5) {
		return jtPurple;
	} else if(random < 6) {
		return jtCyan;
	} else {
		return jtWhite;
	}
}
Пример #27
0
void CTestRangeMap::TestIntervalTree(void) const
{
    Filling("CIntervalTree");

    typedef CIntervalTree TMap;
    typedef TMap::const_iterator TMapCI;

    TMap m;

    // fill
    for ( int count = 0; count < m_RangeNumber; ) {
        TRange range = RandomRange();
        m.Insert(range, CConstRef<CObject>(0));
        ++count;
        Added(range);
    }
    
    if ( m_PrintSize ) {
        Filled(m.Size());
        Stat(m.Stat());
    }

    for ( TMapCI i = m.AllIntervals(); i; ++i ) {
        FromAll(i.GetInterval());
    }

    size_t scannedCount = 0;
    for ( int count = 0; count < m_ScanCount; ++count ) {
        for ( int pos = 0; pos <= m_Length + 2*m_RangeLength;
              pos += m_ScanStep ) {
            TRange range(pos, pos + m_ScanLength - 1);
            
            StartFrom(range);
            
            for ( TMapCI i = m.IntervalsOverlapping(range); i; ++i ) {
                From(range, i.GetInterval());
                ++scannedCount;
            }
        }
    }
    PrintTotalScannedNumber(scannedCount);

    End();
}
Пример #28
0
/**
 * Tries to create a cargo subsidy with an industry as source.
 * @return True iff the subsidy was created.
 */
bool FindSubsidyIndustryCargoRoute()
{
	if (!Subsidy::CanAllocateItem()) return false;

	SourceType src_type = ST_INDUSTRY;

	/* Select a random industry. */
	const Industry *src_ind = Industry::GetRandom();
	if (src_ind == NULL) return false;

	uint trans, total;

	CargoID cid;

	/* Randomize cargo type */
	int num_cargos = 0;
	uint cargo_index;
	for (cargo_index = 0; cargo_index < lengthof(src_ind->produced_cargo); cargo_index++) {
		if (src_ind->produced_cargo[cargo_index] != CT_INVALID) num_cargos++;
	}
	if (num_cargos == 0) return false; // industry produces nothing
	int cargo_num = RandomRange(num_cargos) + 1;
	for (cargo_index = 0; cargo_index < lengthof(src_ind->produced_cargo); cargo_index++) {
		if (src_ind->produced_cargo[cargo_index] != CT_INVALID) cargo_num--;
		if (cargo_num == 0) break;
	}
	assert(cargo_num == 0); // indicates loop didn't break as intended
	cid = src_ind->produced_cargo[cargo_index];
	trans = src_ind->last_month_pct_transported[cargo_index];
	total = src_ind->last_month_production[cargo_index];

	/* Quit if no production in this industry
	 * or if the pct transported is already large enough
	 * or if the cargo is automatically distributed */
	if (total == 0 || trans > SUBSIDY_MAX_PCT_TRANSPORTED ||
			cid == CT_INVALID ||
			_settings_game.linkgraph.GetDistributionType(cid) != DT_MANUAL) {
		return false;
	}

	SourceID src = src_ind->index;

	return FindSubsidyCargoDestination(cid, src_type, src);
}
void change_access_pattern(state_type *state, transaction_descriptor * transaction) {
	int l=0, di_id;
	// Get the client configuration from simulation state
	CLIENT_lp_state_type *pointer = &state->type.client_state;
	operation_descriptor * op= transaction->first_operation;
	do {
			op->object_key_id = -1;
			op=op->next;
	} while(op!=NULL);
	op= transaction->first_operation;
	do {
		do {
			di_id = RandomRange(0, state->cache_objects - 1);
			l = get_operation(transaction, di_id);
		} while (l);
		op->object_key_id=di_id;
		op=op->next;
} while(op!=NULL);
}
Пример #30
0
void RunScope(int count)
{
    for (int i = 0; i < count; ++i)
    {
        int percent = RandomRange(1, 100);
        if (percent <= 15)
            RandomValue();
        else if (percent <= 20)
            g_globalFunction.push_back(RandomFunction());
        else if (percent <= 30)
            g_scopeString.push_back(RandomString());
        else if (percent <= 40)
            g_scopeClosure.push_back(RandomClosure());
        else if (percent <= 50)
            g_scopeTable.push_back(RandomTable());
        else if (percent <= 55)
            NewObjInGlobal();
    }
}