@@ -344,9 +344,8 @@ void AIPlayerJH::PlanNewBuildings(const unsigned gf)
344344 DistributeGoodsByBlocking (GoodType::Boards, 30 );
345345 DistributeGoodsByBlocking (GoodType::Stones, 50 );
346346 // go to the picked random warehouse and try to build around it
347- int randomStore = AI ::randomValue<int >(0 , storehouses.size () - 1 );
348347 auto it = storehouses.begin ();
349- std::advance (it, randomStore );
348+ std::advance (it, AI::randomIndex (storehouses) );
350349 const MapPoint whPos = (*it)->GetPos ();
351350 UpdateNodesAround (whPos, 15 ); // update the area we want to build in first
352351 for (const BuildingType i : bldToTest)
@@ -365,7 +364,7 @@ void AIPlayerJH::PlanNewBuildings(const unsigned gf)
365364 const std::list<nobMilitary*>& militaryBuildings = aii.GetMilitaryBuildings ();
366365 if (militaryBuildings.empty ())
367366 return ;
368- int randomMiliBld = AI ::randomValue <int >(0 , militaryBuildings. size () - 1 );
367+ const int randomMiliBld = static_cast <int >(AI::randomIndex (militaryBuildings) );
369368 auto it2 = militaryBuildings.begin ();
370369 std::advance (it2, randomMiliBld);
371370 MapPoint bldPos = (*it2)->GetPos ();
@@ -1209,7 +1208,7 @@ void AIPlayerJH::HandleExpedition(const noShip* ship)
12091208 aii.FoundColony (ship);
12101209 else
12111210 {
1212- const unsigned offset = AI ::randomValue< unsigned >( 0 , helpers::MaxEnumValue_v<ShipDirection> - 1 );
1211+ const unsigned offset = AI::randomValue ( 0u , helpers::MaxEnumValue_v<ShipDirection> - 1u );
12131212 for (auto dir : helpers::EnumRange<ShipDirection>{})
12141213 {
12151214 dir = ShipDirection ((rttr::enum_cast (dir) + offset) % helpers::MaxEnumValue_v<ShipDirection>);
@@ -1254,7 +1253,7 @@ void AIPlayerJH::HandleTreeChopped(const MapPoint pt)
12541253
12551254 UpdateNodesAround (pt, 3 );
12561255
1257- if (AI ::randomValue< int >( 0 , 1 ) == 0 )
1256+ if (AI::random () )
12581257 AddMilitaryBuildJob (pt);
12591258 else // if (random % 12 == 0)
12601259 AddBuildJob (BuildingType::Woodcutter, pt);
@@ -1536,7 +1535,7 @@ void AIPlayerJH::TryToAttack()
15361535 // We skip the current building with a probability of limit/numMilBlds
15371536 // -> For twice the number of blds as the limit we will most likely skip every 2nd building
15381537 // This way we check roughly (at most) limit buildings but avoid any preference for one building over an other
1539- if (AI ::randomValue< unsigned >( 0 , numMilBlds - 1 ) > limit)
1538+ if (AI::random ( numMilBlds - 1u , limit) )
15401539 continue ;
15411540
15421541 if (milBld->GetFrontierDistance () == FrontierDistance::Far) // inland building? -> skip it
@@ -1569,7 +1568,7 @@ void AIPlayerJH::TryToAttack()
15691568
15701569 // shuffle everything but headquarters and harbors without any troops in them
15711570 std::shuffle (potentialTargets.begin () + hq_or_harbor_without_soldiers, potentialTargets.end (),
1572- std::mt19937 ( AI ::randomValue< unsigned >( 0 , 2047 ) ));
1571+ AI::getRandomGenerator ( ));
15731572
15741573 // check for each potential attacking target the number of available attacking soldiers
15751574 for (const nobBaseMilitary* target : potentialTargets)
@@ -1702,8 +1701,7 @@ void AIPlayerJH::TrySeaAttack()
17021701 unsigned limit = 15 ;
17031702 unsigned skip = 0 ;
17041703 if (searcharoundharborspots.size () > 15 )
1705- skip =
1706- std::max<int >(AI ::randomValue<int >(0 , static_cast <int >(searcharoundharborspots.size () / 15 ) * 15 ), 1 ) - 1 ;
1704+ skip = AI::randomValue (0u , static_cast <unsigned >(searcharoundharborspots.size () / 15u )) * 15u ;
17071705 for (unsigned i = skip; i < searcharoundharborspots.size () && limit > 0 ; i++)
17081706 {
17091707 limit--;
0 commit comments