What would be the best way to create or simulate stocks/crypto price’s.
I’m working on a game that involves the selling/buying of stocks/crypto and want to build almost like a economy around crypto but want it to be stable.
Here’s a bad system I have created that’s sorta unpredictable and non-stable.
local PossibleEvents = {
{Name = "*"},
{Name = "+"},
{Name = "-"}
}
local EventTable = {
{Item = PossibleEvents[2], Weight = 100},
{Item = PossibleEvents[3], Weight = 50},
{Item = PossibleEvents[1], Weight = 15}
}
local function returnSumOfWeight(EventTable)
local sum = 0
for _, entry in ipairs(EventTable) do
sum = sum + entry.Weight
end
return sum
end
local function getRandomAction(EventTable)
local randomNumber = math.random(returnSumOfWeight(EventTable))
for _, entry in ipairs(EventTable) do
if randomNumber <= entry.Weight then
return entry.Item
else
randomNumber = randomNumber - entry.Weight
end
end
end
local Cryptos = script.Cryptos
local YCoin = Cryptos.YCoin
local ZCoin = Cryptos.ZCoin
task.spawn(function()
while task.wait(math.random(3,6)) do
local Action = getRandomAction(EventTable)
if Action.Name == '-' then
YCoin.Price.Value -= math.random(1,20)
elseif Action.Name == '+' then
YCoin.Price.Value += math.random(1,10)
elseif Action.Name == '*' then
print('event (could boost/kill the price)')
end
end
end)