Map.Rand (Civ5 API)

From Civilization Modding Wiki
Jump to navigationJump to search

This page is a part of the Lua and UI Reference (Civ5).


Function.png This function is a member of Map.

This is a static method, invoke it with a dot.
Generates a random number.


Usage

int Map.Rand(int maxValues, string logEntry)


Returned Value

A random number between 0 and maxValues - 1.

Parameters

maxValues: The number of possible random values to make.
logEntry: Not optional, but in what log does this appear? May need to set RandLog = 1 in config.ini.

Wrapper
This is a wrapper function for working with Map.Rand which makes it much easier to use. Returns a random number between lower and upper and including both.

function GetRandom(lower, upper)
	return Map.Rand((upper + 1) - lower, "") + lower
end

Source code samples

Too many occurences. Only 50 out of 668 are listed.

Amazon_XP.lua (G&K)

DLC/Expansion/Maps/Amazon_XP.lua
1134
local diceroll = Map.Rand(10000, "Choose resource type - Assign Luxury To Region - Lua");
1390
local diceroll = Map.Rand(3, "Resource selection - Place Small Quantities LUA");
1417
local strat_radius = Map.Rand(4, "Resource Radius - Place Small Quantities LUA");


Arborea.lua (G&K)

DLC/Expansion/Maps/Arborea.lua
0115
sea_level = 1 + Map.Rand(3, "Random Sea Level - Lua");
0529
local grain_dice = Map.Rand(7, "Continental Grain roll - LUA Continents");
0535
local rift_dice = Map.Rand(3, "Rift Grain roll - LUA Continents");
0679
age = 1 + Map.Rand(3, "Random World Age - Lua");
0721
temp = 1 + Map.Rand(3, "Random Temperature - Lua");


AssignStartingPlots.lua (G&K)

DLC/Expansion/Gameplay/Lua/AssignStartingPlots.lua
4291
local diceroll = 1 + Map.Rand(iNumConversionCandidates, "Choosing plot to convert to Grass near food-poor Plains start - LUA");
4971
local diceroll = 1 + Map.Rand(table.maxn(candidate_regions), "Choosing from among Candidate Regions for start bias - LUA");
7671
res_addition = Map.Rand(1 + (max_radius - min_radius), "Resource Radius - Place Resource LUA");


Boreal.lua (G&K)

DLC/Expansion/Maps/Boreal.lua
0532
x_target = math.floor(iW / 5 + Map.Rand((iW * 0.6), "River Target - Lua"));


Europe.lua (G&K)

DLC/Expansion/Maps/Europe.lua
0074
west_edge[y] = math.ceil(iW * 0.08) - 1 + Map.Rand(4, "Roughen coastline - Mediterranean LUA");


FeatureGenerator.lua (G&K)

DLC/Expansion/Gameplay/Lua/FeatureGenerator.lua
0340
local atoll_number = atoll_target + Map.Rand(atoll_target, "Number of Atolls to place - LUA");
0435
local diceroll = 1 + Map.Rand(100, "Atoll Placement Type - LUA");


FractalWorld.lua

Gameplay/Lua/FractalWorld.lua
0341
local segmentLength = Map.Rand(primaryMaxLength + 1, "FractalWorld Center Rift Segment Length - Lua");
0346
local dice = Map.Rand(2, "FractalWorld Center Rift Direction - Lua");


Great_Plains.lua

Maps/Great_Plains.lua
0179
rightSeed = Map.Rand(5, "Ozarks Shape - Great Plains Lua");
0517
if Map.Rand(100, "Add Oasis Lua") <= 5 then


Hemispheres.lua (G&K)

DLC/Expansion/Maps/Hemispheres.lua
0172
island_setting = 1 + Map.Rand(4, "Random Temperature - Lua");
0389
local x_shrinkage = Map.Rand(8, "Cell Width adjustment - Lua");
0435
local die_1 = Map.Rand(4, "Diceroll - Lua");
0547
local y_shrinkage = Map.Rand(9, "Cell Height adjustment - Lua");
0561
fTilt = 70 + Map.Rand(41, "Angle for island chain axis - LUA");
0580
local iInnerSouth2 = iCellHeight + 2 + Map.Rand(iCellHeight - 3, "Shift for sub island group - Lua");
0615
local iInnerWest1 = 3 + Map.Rand(iCellWidth - 2, "Shift for sub island group - Lua");
0616
local iInnerSouth1 = 3 + Map.Rand(iCellHeight - 2, "Shift for sub island group - Lua");
0683
local iInnerWest2 = 4 + Map.Rand(iCellWidth + 2, "Shift for sub island group - Lua");
0687
local die_2 = Map.Rand(7, "Diceroll - Lua");


Highlands.lua

Maps/Highlands.lua
0093
local shiftRoll = Map.Rand(2, "North or South climate shift - Highlands LUA");
0127
userInputLakes = 1 + Map.Rand(3, "Highlands Random Lake Size - Lua");


IslandMaker.lua

Gameplay/Lua/IslandMaker.lua
0136
local diceroll = Map.Rand(5, "Island Making - Lua");
0202
local randomX = westX + Map.Rand(iInnerWidth, "Random X coord for Dot - Lua");
0259
local randomY = iInnerSouth2 + Map.Rand(iInnerHeight2, "Random Y coord for Dot - Lua");


MapGenerator.lua (G&K)

DLC/Expansion/Gameplay/Lua/MapGenerator.lua
0207
if(plot:IsAdjacentToShallowWater() and Map.Rand(iExpansionDiceroll, "add shallows") == 0) then


MapmakerUtilities.lua

Gameplay/Lua/MapmakerUtilities.lua
0563
local random_index = 1 + Map.Rand(left_to_do, "Shuffling table entry - Lua");


MultilayeredFractal.lua (G&K)

DLC/Expansion/Gameplay/Lua/MultilayeredFractal.lua
0866
local scRoll = Map.Rand((regiononeWidth - scLargeWidth), "Large Subcontinent Placement - Map_Script_Name LUA");


Ring.lua

Maps/Ring.lua
0132
dominant_terrain = 1 + Map.Rand(4, "Random Type of Dominant Terrain - Ring LUA");
0140
bridge_width = 2 + Map.Rand(3, "Random Bridge Width - Ring LUA");


Shuffle.lua (G&K)

DLC/Expansion/Maps/Shuffle.lua
0076
local world_age =  1 + Map.Rand(3, "Random World Age - Lua");
0581
userInputLandmass = 1 + Map.Rand(4, "Random Landmass Type - Lua");
0668
local rain = 1 + Map.Rand(3, "Random Rainfall - Lua");


Skirmish.lua

Maps/Skirmish.lua
0355
local random_factor = Map.Rand(3, "River direction random factor - Skirmish LUA");


Terra.lua

Maps/Terra.lua
0083
local roll1 = Map.Rand(2, "Eurasian Hemisphere N/S - Terra Lua");
0329
local nwcRoll = Map.Rand(2, "Central America and Carribean Placement - Terra Lua");
0432
local scsRoll = Map.Rand((eurasiaWidth - scSmallWidth), "Small Subcontinent Placement - Terra Lua");
0477
local extras = 2 + Map.Rand(3, "Number of Minor Regions - Terra Lua");
0483
local twRoll = Map.Rand((eurasiaWidth - twWidth), "Minor Region Placement - Terra Lua");


WorldBuilderRandomItems.lua

Gameplay/Lua/WorldBuilderRandomItems.lua
0018
local rand1 = Map.Rand(resource.RandApp1, "MapGenerator CalculateNumResourcesToAdd-1");
0021
local rand4 = Map.Rand(resource.RandApp4, "MapGenerator CalculateNumResourcesToAdd-4");



The initial version of this page was created by the Civ5 API Bot, see the Civ5 API Reference FAQ. Some of the texts come from the 2kgames' wiki and most of code samples are copyrighted to Firaxis.
Functions' signatures were either copied from the 2kgames' wiki, or infered from the Lua source files and the binaries. Errors are possible.
Contributors may find help in the Contributors guide to the Civ5 API.