Procedural Generation with Math.Random()

I am currently trying to create a primitive procedural generation script with Math.Random(). It seems to have a few bugs, and I am at a loss of what to do. My current code is this:

function GenerateRandom (seed,max)
  local store = {}

  for i = 1, max/5 do
    math.randomseed(seed)
    for b = 1, 5 do
      store[(i-1)*5 + b] = math.ceil(math.random() * 100000000000000)
      seed = math.random() * 100000000000000
    end
    print(seed)
  end

  return store
end

local list = GenerateRandom(os.time(),100)

When I run it, it should theoretically generate new numbers every time, because I am setting a new seed every time it generates a number. However, this is not the case, and it seems to generate a repeating set. This should not be the case. I am wondering if anyone can point out any issues with my code. Any help would be appreciated!

2 Likes

Your algorithm just fundamentally sets the same seed repeatedly.

1 Like

Actually no it doesn’t this should work, and it does in my lua install. It might be something weird with how roblox implements math.random.

1 Like

Have you tried using Random library? I believe it is more up-to date than math.random() and math.randomseed()

This seems to be the answer. Math.randomSeed() doesn’t correctly set the seed in Roblox. Random.new() actually works. I actually was using code that I built on a separate platform (lua somewhere else), which may be why Roblox doesn’t run the code properly.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.