Index: binaries/data/mods/public/globalscripts/random.js
===================================================================
--- binaries/data/mods/public/globalscripts/random.js	(nonexistent)
+++ binaries/data/mods/public/globalscripts/random.js	(working copy)
@@ -0,0 +1,43 @@
+/*
+ * Return a random floating point number using Math.random library
+ *
+ * If no parameter given, the returned float is in the interval [0, 1)
+ * If one parameter given, it's maxval, and the returned float is in the interval [0, maxval)
+ * If two parameters are given, they are minval and maxval, and the returned float is in the interval [minval, maxval)
+ */
+function randFloat()
+{
+	if (!arguments.length)
+		return Math.random();
+	else if (arguments.length == 1)
+		return randFloat() * arguments[0];
+	else if (arguments.length == 2)
+		return arguments[0] + randFloat() * (arguments[1] - arguments[0]);
+	else
+	{
+		error("randFloat: invalid number of arguments: "+arguments.length);
+		return undefined;
+	}
+}
+
+/*
+ * Return a random integer using Math.random library
+ *
+ * If no parameter given, the returned integer is in the interval [0 .. 1]
+ * If one parameter given, it's maxval, and the returned integer is in the interval [0 .. maxval-1]
+ * If two parameters are given, they are minval and maxval, and the returned integer is in the interval [minval .. maxval]
+ */
+function randInt()
+{
+	if (!arguments.length)
+		return Math.round(randFloat());
+	else if (arguments.length == 1)
+		return Math.floor(randFloat(arguments[0]));
+	else if (arguments.length == 2)
+		return Math.floor(randFloat(arguments[0], arguments[1] + 1));
+	else
+	{
+		error("randInt: invalid number of arguments: "+arguments.length);
+		return undefined;
+	}
+}
Index: binaries/data/mods/public/globalscripts/utility.js
===================================================================
--- binaries/data/mods/public/globalscripts/utility.js	(revision 18650)
+++ binaries/data/mods/public/globalscripts/utility.js	(working copy)
@@ -28,9 +28,14 @@
 	let result = [source[0]];
 	for (let i = 1; i < source.length; ++i)
 	{
-		let j = Math.floor(Math.random() * (i+1));
+		let j = randInt(i+1);
 		result[i] = result[j];
 		result[j] = source[i];
 	}
 	return result;
 }
+
+function pickRandom(source)
+{
+	return source.length ? source[randInt(source.length)] : undefined;
+}
Index: binaries/data/mods/public/gui/common/functions_utility.js
===================================================================
--- binaries/data/mods/public/gui/common/functions_utility.js	(revision 18650)
+++ binaries/data/mods/public/gui/common/functions_utility.js	(working copy)
@@ -3,16 +3,6 @@
  */
 var g_LastNickNotification = -1;
 
-function getRandom(randomMin, randomMax)
-{
-	// Returns a random whole number in a min..max range.
-	// NOTE: There should probably be an engine function for this,
-	// since we'd need to keep track of random seeds for replays.
-
-	var randomNum = randomMin + (randomMax-randomMin)*Math.random();  // num is random, from A to B
-	return Math.round(randomNum);
-}
-
 // Get list of XML files in pathname with recursion, excepting those starting with _
 function getXMLFileList(pathname)
 {
Index: binaries/data/mods/public/gui/common/music.js
===================================================================
--- binaries/data/mods/public/gui/common/music.js	(revision 18650)
+++ binaries/data/mods/public/gui/common/music.js	(working copy)
@@ -132,7 +132,7 @@
 
 Music.prototype.getRandomTrack = function(tracks)
 {
-	return tracks[getRandom(0, tracks.length-1)];
+	return pickRandom(tracks);
 };
 
 Music.prototype.startPlayList = function(tracks, fadeInPeriod, isLooping)
Index: binaries/data/mods/public/gui/gamesetup/gamesetup.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/gamesetup.js	(revision 18650)
+++ binaries/data/mods/public/gui/gamesetup/gamesetup.js	(working copy)
@@ -1229,8 +1229,7 @@
 	{
 		let victoryScriptsSelected = g_GameAttributes.settings.VictoryScripts;
 		let gameTypeSelected = g_GameAttributes.settings.GameType;
-		selectMap(Engine.GetGUIObjectByName("mapSelection").list_data[Math.floor(Math.random() *
-			(Engine.GetGUIObjectByName("mapSelection").list.length - 1)) + 1]);
+		selectMap(pickRandom(Engine.GetGUIObjectByName("mapSelection").list_data));
 		g_GameAttributes.settings.VictoryScripts = victoryScriptsSelected;
 		g_GameAttributes.settings.GameType = gameTypeSelected;
 	}
@@ -1253,9 +1252,9 @@
 		let chosenCiv = g_GameAttributes.settings.PlayerData[i].Civ || "random";
 		if (chosenCiv == "random")
 		{
-			let culture = cultures[Math.floor(Math.random() * cultures.length)];
+			let culture = pickRandom(cultures);
 			let civs = Object.keys(g_CivData).filter(civ => g_CivData[civ].Culture == culture);
-			chosenCiv = civs[Math.floor(Math.random() * civs.length)];
+			chosenCiv = pickRandom(civs);
 		}
 		g_GameAttributes.settings.PlayerData[i].Civ = chosenCiv;
 
@@ -1263,7 +1262,7 @@
 		if (g_GameAttributes.mapType === "scenario" || !g_GameAttributes.settings.PlayerData[i].AI)
 			continue;
 
-		let chosenName = g_CivData[chosenCiv].AINames[Math.floor(Math.random() * g_CivData[chosenCiv].AINames.length)];
+		let chosenName = pickRandom(g_CivData[chosenCiv].AINames);
 
 		if (!g_IsNetworked)
 			chosenName = translate(chosenName);
Index: binaries/data/mods/public/gui/loading/loading.js
===================================================================
--- binaries/data/mods/public/gui/loading/loading.js	(revision 18650)
+++ binaries/data/mods/public/gui/loading/loading.js	(working copy)
@@ -14,7 +14,7 @@
 	if (tipTextLoadingArray.length > 0)
 	{
 		// Set tip text
-		let tipTextFilePath = tipTextLoadingArray[getRandom(0, tipTextLoadingArray.length-1)];
+		let tipTextFilePath = pickRandom(tipTextLoadingArray);
 		let tipText = Engine.TranslateLines(Engine.ReadFile(tipTextFilePath));
 
 		if (tipText)
@@ -63,7 +63,7 @@
 
 	// Pick a random quote of the day (each line is a separate tip).
 	let quoteArray = Engine.ReadFileLines("gui/text/quotes.txt");
-	Engine.GetGUIObjectByName("quoteText").caption = translate(quoteArray[getRandom(0, quoteArray.length-1)]);
+	Engine.GetGUIObjectByName("quoteText").caption = translate(pickRandom(quoteArray));
 }
 
 function displayProgress()
Index: binaries/data/mods/public/maps/random/flood.js
===================================================================
--- binaries/data/mods/public/maps/random/flood.js	(revision 18650)
+++ binaries/data/mods/public/maps/random/flood.js	(working copy)
@@ -445,7 +445,7 @@
 	planetm * scaleByMapSize(13, 200)
 );
 
-setSkySet(shuffleArray(["cloudless", "cumulus", "overcast"])[0]);
+setSkySet(pickRandom(["cloudless", "cumulus", "overcast"]));
 setWaterMurkiness(0.4);
 
 ExportMap();
Index: binaries/data/mods/public/maps/random/island_stronghold.js
===================================================================
--- binaries/data/mods/public/maps/random/island_stronghold.js	(revision 18650)
+++ binaries/data/mods/public/maps/random/island_stronghold.js	(working copy)
@@ -577,7 +577,7 @@
 paintTerrainBasedOnHeight(1, 2, 0, tShore);
 paintTerrainBasedOnHeight(getMapBaseHeight(), 1, 3, tWater);
 
-setSkySet(shuffleArray(["cloudless", "cumulus", "overcast"])[0]);
+setSkySet(pickRandom(["cloudless", "cumulus", "overcast"]));
 
 setSunRotation(randFloat(0, TWO_PI));
 setSunElevation(randFloat(PI/5, PI/3));
Index: binaries/data/mods/public/maps/random/rmgen/random.js
===================================================================
--- binaries/data/mods/public/maps/random/rmgen/random.js	(revision 18650)
+++ binaries/data/mods/public/maps/random/rmgen/random.js	(nonexistent)
@@ -1,54 +0,0 @@
-// TODO: rename/change these functions, so the bounds are more clear
-
-/*
- * Return a random floating point number using Math.random library
- *
- * If no parameter given, the returned float is in the interval [0, 1)
- * If two parameters are given, they are minval and maxval, and the returned float is in the interval [minval, maxval)
- */
-function randFloat()
-{
-	if (arguments.length == 0)
-	{
-		return Math.random();
-	}
-	else if (arguments.length == 2)
-	{
-		var minVal = arguments[0]; 
-		var maxVal = arguments[1];
-		
-		return minVal + randFloat() * (maxVal - minVal);
-	}
-	else
-	{
-		error("randFloat: invalid number of arguments: "+arguments.length);
-		return undefined;
-	}
-}
-
-/*
- * Return a random integer using Math.random library
- *
- * If one parameter given, it's maxval, and the returned integer is in the interval [0, maxval)
- * If two parameters are given, they are minval and maxval, and the returned integer is in the interval [minval, maxval]
- */
-function randInt()
-{	
-	if (arguments.length == 1)
-	{
-		var maxVal = arguments[0]; 
-		return Math.floor(Math.random() * maxVal);
-	}
-	else if (arguments.length == 2)
-	{
-		var minVal = arguments[0];
-		var maxVal = arguments[1];
-		
-		return minVal + randInt(maxVal - minVal + 1);
-	}
-	else
-	{
-		error("randInt: invalid number of arguments: "+arguments.length);
-		return undefined;
-	}
-}

Property changes on: binaries/data/mods/public/maps/random/rmgen/random.js
___________________________________________________________________
Deleted: svn:eol-style
## -1 +0,0 ##
-native
\ No newline at end of property
Index: binaries/data/mods/public/simulation/ai/common-api/utils.js
===================================================================
--- binaries/data/mods/public/simulation/ai/common-api/utils.js	(revision 18650)
+++ binaries/data/mods/public/simulation/ai/common-api/utils.js	(working copy)
@@ -54,13 +54,6 @@
 	return endArray;
 };
 
-/** Picks a random element from an array */
-m.PickRandom = function(list)
-{
-	return list.length ? list[Math.floor(Math.random()*list.length)] : undefined;
-};
-
-
 /** Utility functions for conversions of maps of different sizes */
 
 /**
Index: binaries/data/mods/public/simulation/ai/petra/chatHelper.js
===================================================================
--- binaries/data/mods/public/simulation/ai/petra/chatHelper.js	(revision 18650)
+++ binaries/data/mods/public/simulation/ai/petra/chatHelper.js	(working copy)
@@ -3,127 +3,89 @@
 
 m.chatLaunchAttack = function(gameState, player, type)
 {
-	let message;
-	let proba = Math.random();
-	if (type === "HugeAttack" && proba > 0.25 && proba < 0.75)
-		message = "/team " + markForTranslation("I am starting a massive military campaign against %(_player_)s, come and join me.");
-	else if (proba < 0.5)
-		message = "/team " + markForTranslation("I am launching an attack against %(_player_)s.");
-	else
-		message = "/team " + markForTranslation("I have just sent an army against %(_player_)s.");
-
 	Engine.PostCommand(PlayerID, {
 		"type": "aichat",
-		"message": message,
+		"message": "/allies " + (type === "HugeAttack" && Math.random() < 0.5 ?
+			markForTranslation("I am starting a massive military campaign against %(_player_)s, come and join me.") :
+			pickRandom([
+				markForTranslation("I am launching an attack against %(_player_)s."),
+				markForTranslation("I have just sent an army against %(_player_)s.")
+			])),
 		"translateMessage": true,
 		"translateParameters": ["_player_"],
-		"parameters": {"_player_": player}
+		"parameters": { "_player_": player }
 	});
 };
 
 m.chatAnswerRequestAttack = function(gameState, player, answer, other)
 {
-	let message;
-	if (answer)
-	{
-		let proba = Math.random();
-		if (proba < 0.5)
-			message = "/allies " + markForTranslation("Let me regroup my army and I am with you against %(_player_)s.");
-		else
-			message = "/allies " + markForTranslation("I am doing the final preparation and I will attack %(_player_)s.");
-	}
-	else
-	{
-		if (other !== undefined)
-			message = "/allies " + markForTranslation("I cannot help you against %(_player_)s for the time being, as I have another attack foreseen against %(_player_2)s.");
-		else
-			message = "/allies " + markForTranslation("Sorry, I do not have enough soldiers currently, but my next attack will target %(_player_)s.");
-	}
-
-	let chat = {
+	Engine.PostCommand(PlayerID, {
 		"type": "aichat",
-		"message": message,
+		"message": "/allies " + (answer ?
+			pickRandom([
+				markForTranslation("Let me regroup my army and I am with you against %(_player_)s."),
+				markForTranslation("I am doing the final preparation and I will attack %(_player_)s.")
+			]) :
+			(other ?
+				markForTranslation("I cannot help you against %(_player_)s for the time being, as I have another attack foreseen against %(_player_2)s.") :
+				markForTranslation("Sorry, I do not have enough soldiers currently, but my next attack will target %(_player_)s."))),
 		"translateMessage": true,
-		"translateParameters": ["_player_"],
-		"parameters": {"_player_": player}
-	};
-	if (other !== undefined)
-	{
-		chat.translateParameters.push("_player_2");
-		chat.parameters._player_2 = other;
-	}
-	Engine.PostCommand(PlayerID, chat);
+		"translateParameters": other ? ["_player_", "_player_2"] : ["_player_"],
+		"parameters": other ? { "_player_": player, "_player2_": other } : { "_player_": player }
+	});
 };
 
 m.chatSentTribute = function(gameState, player)
 {
-	let message;
-	let proba = Math.random();
-	if (proba < 0.33)
-		message = "/team " + markForTranslation("Here is a gift for %(_player_)s, make a good use of it.");
-	else if (proba < 0.66)
-		message = "/team " + markForTranslation("I see you are in a bad situation %(_player_)s, I hope this will help."); 
-	else
-		message = "/team " + markForTranslation("I can help you this time %(_player_)s, but try to assemble more resources in the future.");
-
 	Engine.PostCommand(PlayerID, {
 		"type": "aichat",
-		"message": message,
+		"message": "/allies " + pickRandom([
+			markForTranslation("Here is a gift for %(_player_)s, make a good use of it."),
+			markForTranslation("I see you are in a bad situation %(_player_)s, I hope this will help."),
+			markForTranslation("I can help you this time %(_player_)s, but try to assemble more resources in the future.")
+		]),
 		"translateMessage": true,
 		"translateParameters": ["_player_"],
-		"parameters": {"_player_": player}
+		"parameters": { "_player_": player }
 	});
 };
 
 m.chatRequestTribute = function(gameState, resource)
 {
-	let message;
-	let proba = Math.random();
-	if (proba < 0.33)
-		message = "/team " + markForTranslation("I am in need of %(resource)s, can you help? I will make it up to you.");
-	else if (proba < 0.66)
-		message = "/team " + markForTranslation("I would participate more efficiently in our common war effort if you could provide me some %(resource)s.");
-	else
-		message = "/team " + markForTranslation("If you have some %(resource)s excess, that would help me strengthen my army.");
-
 	Engine.PostCommand(PlayerID, {
 		"type": "aichat",
-		"message": message,
+		"message": "/allies " + pickRandom([
+			markForTranslation("I am in need of %(resource)s, can you help? I will make it up to you."),
+			markForTranslation("I would participate more efficiently in our common war effort if you could provide me some %(resource)s."),
+			markForTranslation("If you have some %(resource)s excess, that would help me strengthen my army.")
+		]),
 		"translateMessage": true,
-		"translateParameters": {"resource": "withinSentence"},
-		"parameters": {"resource": gameState.sharedScript.resourceNames[resource]}
+		"translateParameters": { "resource": "withinSentence" },
+		"parameters": { "resource": gameState.sharedScript.resourceNames[resource] }
 	});
 };
 
 m.chatNewTradeRoute = function(gameState, player)
 {
-	let message;
-	let proba = Math.random();
-	if (proba < 0.5)
-		message = "/team " + markForTranslation("I have set up a new route with %(_player_)s. Trading will be profitable for all of us.");
-	else
-		message = "/team " + markForTranslation("A new trade route is set up with %(_player_)s. Take your share of the profits");
-
 	Engine.PostCommand(PlayerID, {
 		"type": "aichat",
-		"message": message,
+		"message": "/allies " + pickRandom([
+			markForTranslation("I have set up a new route with %(_player_)s. Trading will be profitable for all of us."),
+			markForTranslation("A new trade route is set up with %(_player_)s. Take your share of the profits")
+		]),
 		"translateMessage": true,
 		"translateParameters": ["_player_"],
-		"parameters": {"_player_": player}
+		"parameters": { "_player_": player }
 	});
 };
 
 m.chatNewPhase = function(gameState, phase, started)
 {
-	let message;
-	if (started)
-		message = "/allies " + markForTranslation("I am advancing to the %(phase)s.");
-	else
-		message = "/allies " + markForTranslation("I have reached the %(phase)s.");
-
 	Engine.PostCommand(PlayerID, {
 		"type": "aichat",
-		"message": message,
+		"message": "/allies " + (started ?
+			markForTranslation("I am advancing to the %(phase)s.") :
+			markForTranslation("I have reached the %(phase)s.")),
 		"translateMessage": true,
 		"translateParameters": ["phase"],
 		"parameters": { "phase": phase }
Index: binaries/data/mods/public/simulation/components/UnitAI.js
===================================================================
--- binaries/data/mods/public/simulation/components/UnitAI.js	(revision 18650)
+++ binaries/data/mods/public/simulation/components/UnitAI.js	(working copy)
@@ -3115,7 +3115,7 @@
 				this.SelectAnimation("walk", false, this.GetWalkSpeed());
 				this.MoveRandomly(+this.template.RoamDistance);
 				// Set a random timer to switch to feeding state
-				this.StartTimer(RandomInt(+this.template.RoamTimeMin, +this.template.RoamTimeMax));
+				this.StartTimer(randInt(+this.template.RoamTimeMin, +this.template.RoamTimeMax));
 				this.SetFacePointAfterMove(false);
 			},
 
@@ -3160,7 +3160,7 @@
 				// Stop and eat for a while
 				this.SelectAnimation("feeding");
 				this.StopMoving();
-				this.StartTimer(RandomInt(+this.template.FeedTimeMin, +this.template.FeedTimeMax));
+				this.StartTimer(randInt(+this.template.FeedTimeMin, +this.template.FeedTimeMax));
 			},
 
 			"leave": function() {
Index: binaries/data/mods/public/simulation/helpers/Random.js
===================================================================
--- binaries/data/mods/public/simulation/helpers/Random.js	(revision 18650)
+++ binaries/data/mods/public/simulation/helpers/Random.js	(nonexistent)
@@ -1,9 +0,0 @@
-/**
- * Returns a random integer from min (inclusive) to max (exclusive)
- */
-function RandomInt(min, max)
-{
-	return Math.floor(min + Math.random() * (max-min));
-}
-
-Engine.RegisterGlobal("RandomInt", RandomInt);

Property changes on: binaries/data/mods/public/simulation/helpers/Random.js
___________________________________________________________________
Deleted: svn:eol-style
## -1 +0,0 ##
-native
\ No newline at end of property
