Unoptimized RNG problem

The problem with my Current RNG script is that I create new Random objects each time you create a custom rng.

I can use math.random() and math.randomseed() for this, but they are only 32 bit instead of 64 bit.

(if this was a feature request i would ask for a Random.new():ChangeSeed() function, but i cant make them, so)

any workarounds?

thanks.

(RNG)

type Seeds = {

number | string

}

local Min = -9007199254740991
local Max = 9007199254740991
local Range = Max - Min

local RNG = {}

RNG.WrapNumber = function (Number)

local Result = (Number - Min) % Range + Min

if Result > Max then

  Result = Result - Range

end

return Result

end

RNG.HashString = function (String : string)

local Hash = 2166136261

for Index = 1, string do

  Hash = bit32.bxor(Hash, string.byte(String, Index)) * 16777619 
  Hash = RNG.WrapNumber(Hash)

end

return Hash

end

RNG.new = function (Seeds : Seeds)

local CombinedSeeds = “”

for Index = 1, #Seeds do

  local Seed = Seeds[Index]
  
  CombinedSeeds = CombinedSeeds .. tostring(Seed)

end

return Random.new(RNG.HashString(CombinedSeeds))

end

return RNG

I don’t think there’s a way to set the seed of a Random object after its creation; I would recommend making your own PRNG if you need the ability to set a new seed.

there is resources here for random generation, you can check them out

the problem is that is too hard :sob:

The worst performance you could get similarly is creating cframes, meaning creating 10 million cframes in 1 frame would take like a second. If you want to change seed while keeping the same random count, create your own random function, otherwise you are fine.

no thats not the problem, the problem is that you cant change the seed of an existing random object

i get that the preformance difference is not by much, but it still kinda worries me.
creating my own psuedo-random generator is too hard, but if its probably the only option i’ll have to look into it

There are probably open-source PRNGs you can look into.

Relatable, but believe me, there are more heavier operations going in your projects, you can close eyes on this problem with confidence. At the other hand, you will learn better knowledge by creating your own functions, taking inspirations from free sources is always welcome

as said, yeah i should probably make my own prng,
thanks yall.