Index: binaries/data/mods/public/simulation/ai/common-api/shared.js
===================================================================
--- binaries/data/mods/public/simulation/ai/common-api/shared.js	(révision 15966)
+++ binaries/data/mods/public/simulation/ai/common-api/shared.js	(copie de travail)
@@ -6,6 +6,11 @@
 {
 	if (!settings)
 		return;
+
+	// TODO should be replaced by a seeded random generator 
+	if (settings.seed)
+		for (let i = 0; i < settings.seed%1000; ++i)
+			Math.random();
 	
 	this._players = settings.players;
 	this._templates = settings.templates;
Index: binaries/data/mods/public/simulation/helpers/InitGame.js
===================================================================
--- binaries/data/mods/public/simulation/helpers/InitGame.js	(révision 15966)
+++ binaries/data/mods/public/simulation/helpers/InitGame.js	(copie de travail)
@@ -51,7 +51,8 @@
 			cmpPlayer.SetResourceCounts(newResourceCounts);
 		}
 	}
-	cmpAIManager.TryLoadSharedComponent();
+	let randomSeed = settings.Seed ? settings.Seed : 0;
+	cmpAIManager.TryLoadSharedComponent(randomSeed);
 	cmpAIManager.RunGamestateInit();
 }
 
Index: source/ps/GameSetup/GameSetup.cpp
===================================================================
--- source/ps/GameSetup/GameSetup.cpp	(révision 15966)
+++ source/ps/GameSetup/GameSetup.cpp	(copie de travail)
@@ -1162,17 +1162,17 @@
  * Command line options for autostart (keep synchronized with readme.txt):
  *
  * -autostart="TYPEDIR/MAPNAME"		enables autostart and sets MAPNAME; TYPEDIR is skirmishes, scenarios, or random
- * -autostart-ai=PLAYER:AI			sets the AI for PLAYER (e.g. 2:petra)
+ * -autostart-ai=PLAYER:AI	       	sets the AI for PLAYER (e.g. 2:petra)
  * -autostart-aidiff=PLAYER:DIFF	sets the DIFFiculty of PLAYER's AI (0: easy, 3: very hard)
  * -autostart-civ=PLAYER:CIV		sets PLAYER's civilisation to CIV (skirmish and random maps only)
+ * -autostart-seed=SEED			sets (AI + random map) SEED value (default 0, use -1 for random)
  * Multiplayer:
  * -autostart-playername=NAME		sets local player NAME (default 'anonymous')
- * -autostart-host					sets multiplayer host mode
+ * -autostart-host		      	sets multiplayer host mode
  * -autostart-host-players=NUMBER	sets NUMBER of human players for multiplayer game (default 2)
- * -autostart-client=IP				sets multiplayer client to join host at given IP address
+ * -autostart-client=IP			sets multiplayer client to join host at given IP address
  * Random maps only:
- * -autostart-seed=SEED				sets random map SEED value (default 0, use -1 for random)
- * -autostart-size=TILES			sets random map size in TILES (default 192)
+ * -autostart-size=TILES		sets random map size in TILES (default 192)
  * -autostart-players=NUMBER		sets NUMBER of players on random map (default 2)
  *
  * Examples:
@@ -1218,19 +1218,6 @@
 
 	if (mapDirectory == L"random")
 	{
-		// Default seed is 0
-		u32 seed = 0;
-		CStr seedArg = args.Get("autostart-seed");
-
-		if (!seedArg.empty())
-		{
-			// Random seed value
-			if (seedArg != "-1")
-				seed = rand();
-			else
-				seed = seedArg.ToULong();
-		}
-		
 		// Random map definition will be loaded from JSON file, so we need to parse it
 		std::wstring scriptPath = L"maps/" + autoStartName.FromUTF8() + L".json";
 		JS::RootedValue scriptData(cx);
@@ -1257,7 +1244,6 @@
 			mapSize = size.ToUInt();
 		}
 
-		scriptInterface.SetProperty(settings, "Seed", seed);		// Random seed
 		scriptInterface.SetProperty(settings, "Size", mapSize);		// Random map size (in patches)
 
 		// Get optional number of players (default 2)
@@ -1307,6 +1293,19 @@
 	scriptInterface.SetProperty(attrs, "map", std::string("maps/" + autoStartName));
 	scriptInterface.SetProperty(settings, "mapType", mapType);
 
+	// Random seed value for random maps and AIs, default is 0
+	u32 seed = 0;
+	if (args.Has("autostart-seed"))
+       	{
+	       	CStr seedArg = args.Get("autostart-seed");
+       		if (seedArg == "-1")
+       			seed = rand();
+	       	else
+	       		seed = seedArg.ToULong();
+       		LOGWARNING(L"Autostart: random seed %d ", seed);
+       	}
+       	scriptInterface.SetProperty(settings, "Seed", seed);
+
 	// Set player data for AIs
 	//		attrs.settings = { PlayerData: [ { AI: ... }, ... ] }:
 	if (args.Has("autostart-ai"))
Index: source/simulation2/components/CCmpAIManager.cpp
===================================================================
--- source/simulation2/components/CCmpAIManager.cpp	(révision 15966)
+++ source/simulation2/components/CCmpAIManager.cpp	(copie de travail)
@@ -361,7 +361,7 @@
 		tex_write(&t, filename);
 	}
 
-	bool TryLoadSharedComponent(bool hasTechs)
+	bool TryLoadSharedComponent(bool hasTechs, uint32_t randomSeed)
 	{
 		JSContext* cx = m_ScriptInterface->GetContext();
 		JSAutoRequest rq(cx);
@@ -412,6 +412,7 @@
 			m_ScriptInterface->SetPropertyInt(playersID, i, val, true);
 		}
 		
+		m_ScriptInterface->SetProperty(settings, "seed", randomSeed);
 		m_ScriptInterface->SetProperty(settings, "players", playersID);
 		ENSURE(m_HasLoadedEntityTemplates);
 		m_ScriptInterface->SetProperty(settings, "templates", m_EntityTemplates, false);
@@ -671,7 +672,7 @@
 		deserializer.NumberU32_Unbounded("num ais", numAis);
 
 		deserializer.Bool("useSharedScript", m_HasSharedComponent);
-		TryLoadSharedComponent(false);
+		TryLoadSharedComponent(false, 0);
 		if (m_HasSharedComponent)
 		{
 			JS::RootedValue sharedData(cx);
@@ -917,7 +918,7 @@
 			cmpRangeManager->SetLosRevealAll(player, true);
 	}
 	
-	virtual void TryLoadSharedComponent()
+	virtual void TryLoadSharedComponent(uint32_t randomSeed)
 	{
 		ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface();
 		JSContext* cx = scriptInterface.GetContext();
@@ -931,7 +932,7 @@
 		JS::RootedValue techTemplates(cx, cmpTechTemplateManager->GetAllTechs().get());
 		
 		m_Worker.RegisterTechTemplates(scriptInterface.WriteStructuredClone(techTemplates));
-		m_Worker.TryLoadSharedComponent(true);
+		m_Worker.TryLoadSharedComponent(true, randomSeed);
 	}
 
 	virtual void RunGamestateInit()
Index: source/simulation2/components/ICmpAIManager.cpp
===================================================================
--- source/simulation2/components/ICmpAIManager.cpp	(révision 15966)
+++ source/simulation2/components/ICmpAIManager.cpp	(copie de travail)
@@ -26,7 +26,7 @@
 
 BEGIN_INTERFACE_WRAPPER(AIManager)
 DEFINE_INTERFACE_METHOD_3("AddPlayer", void, ICmpAIManager, AddPlayer, std::wstring, player_id_t, uint8_t)
-DEFINE_INTERFACE_METHOD_0("TryLoadSharedComponent", void, ICmpAIManager, TryLoadSharedComponent)
+DEFINE_INTERFACE_METHOD_1("TryLoadSharedComponent", void, ICmpAIManager, TryLoadSharedComponent, uint32_t)
 DEFINE_INTERFACE_METHOD_0("RunGamestateInit", void, ICmpAIManager, RunGamestateInit)
 END_INTERFACE_WRAPPER(AIManager)
 
Index: source/simulation2/components/ICmpAIManager.h
===================================================================
--- source/simulation2/components/ICmpAIManager.h	(révision 15966)
+++ source/simulation2/components/ICmpAIManager.h	(copie de travail)
@@ -31,7 +31,7 @@
 	 * to control player @p player.
 	 */
 	virtual void AddPlayer(std::wstring id, player_id_t player, uint8_t difficulty) = 0;
-	virtual void TryLoadSharedComponent() = 0;
+	virtual void TryLoadSharedComponent(uint32_t randomSeed) = 0;
 	virtual void RunGamestateInit() = 0;
 
 	/**
