working on a random gen script and it works although the variation between rolls isn’t that far apart, usually only about 10~ with 1000 rolls, i’m looking to get a decent more than this
currently the script rolls of off
- if theres enough weight for the path
- Chance
for example, longpath1 has 5 weight, and a 20% chance to roll. each roll the weight increases by 1-3, for longpath1 to generate there has to be atleast 5 or more weight and on generation it removes 5 weight
for Path, PathInfo in pairs(Thingy) do
if PathInfo.Weight <= CurrentWeight then
local ChanceMult = {}
local Chance = PathInfo.Chance
local SpareWeight = CurrentWeight - PathInfo.Weight
local Rolls = RollsSinceRolled[Path] - 5
local Mullipier = 1
if SpareWeight > 0 then
table.insert(ChanceMult, SpareWeight/55)
end
if Rolls > 0 then
table.insert(ChanceMult, Rolls/5)
end
for i, v in ipairs(ChanceMult) do
Mullipier += v
end
local ModifiedChance = Chance * Mullipier
CanRoll[Path] = ModifiedChance
end
end
this basically helps lower chance paths be picked easier by
- if the current weight is over the amount it takes to roll it, boost the rng
- if it hasnt been rolled in over 5 rolls it boosts its rng
this does benefit the paths but doesnt have much variation behind it
so im asking on how i could add more variation to this
Full scripts
local GenerationValues = require(script.GenValues)
local FloorAssets = game:GetService("ServerStorage").FloorAssets
local RunService = game:GetService('RunService')
local FloorStatuses = {}
local function RNGd(Thingy, CurrentWeight, RollsSinceRolled)
local CanRoll = {}
local Rng = Random.new()
local Counter = 0
for Path, PathInfo in pairs(Thingy) do
if PathInfo.Weight <= CurrentWeight then
local ChanceMult = {}
local Chance = PathInfo.Chance
local SpareWeight = CurrentWeight - PathInfo.Weight
local Rolls = RollsSinceRolled[Path] - 5
local Mullipier = 1
if SpareWeight > 0 then
table.insert(ChanceMult, SpareWeight/55)
end
if Rolls > 0 then
table.insert(ChanceMult, Rolls/5)
end
for i, v in ipairs(ChanceMult) do
Mullipier += v
end
local ModifiedChance = Chance * Mullipier
CanRoll[Path] = ModifiedChance
end
end
for _, Chance in pairs(CanRoll) do
Counter += Chance
end
local Chosen = Rng:NextNumber(0, Counter)
for Path, Chance in pairs(CanRoll) do
Counter -= Chance
if Chosen > Counter then
return Path
end
end
end
local GenerationModule = {}
GenerationModule.StartGeneration = function()
local Weight = 0
local Rooms = 5
local RollsSinceRolled = {}
local FloorValues = GenerationValues.Floor1
for Path, _ in pairs(FloorValues) do
RollsSinceRolled[Path] = 0
end
local D = {}
for i=1,1000 do
local Roll = RNGd(FloorValues, Weight, RollsSinceRolled)
Weight -= FloorValues[Roll].Weight
for Path, Num in pairs(RollsSinceRolled) do
if Path ~= Roll then
RollsSinceRolled[Path] += 1
else
RollsSinceRolled[Path] = 0
end
end
Weight += math.random(1,3)
if not D[Roll] then D[Roll] = 1 else D[Roll] +=1 end
end
print(D)
end
GenerationModule.__index = GenerationModule
return GenerationModule
local FloorGens = game:GetService("ServerStorage").FloorAssets
local Floor1 = FloorGens.Floor1GEN
local Gvalues= {
["Floor1"] = {
["DoubleTurn"] = {["Weight"] = 9, ["Chance"] = 25},
["longpath1"] = {["Weight"] = 5, ["Chance"] = 20},
["square1"] = {["Weight"] = 0, ["Chance"] = 100}
}
}
return Gvalues