function module:RandomKey(Table,seed : number)
local rng = Random.new(seed or 55)
assert(typeof(Table) == "table",script.Name.." Error: Function RandomKey did not receive a table.")
local selectedIndex_Key = rng:NextInteger(1,#Table)
print(selectedIndex_Key)
local selectedValue = Table[selectedIndex_Key]
local final = {
Key = selectedIndex_Key,
Value = selectedValue
}
return final
end
I have a table for the argument, which is a dictionary like this:
local module = require(script.ModuleScript)
local a = {"a","b","c"}
while wait(1) do
local random = module:RandomKey(a)
print(random["Key"], random["Value"])
end
However, everytime it prints the key and value, it’s always the same. It keeps printing 3 c and not the other contents inside the table. Am I doing something wrong?
EDIT: Turns out it’s the seed 55 that ruined the problem, so I didn’t add any seeds inside the Random.new()
argument and it solves the problem, however whenever I add a random number, it will only keep printing that one number. Anyone can explain this?