Math.random questions (performance wise)

[deleted for project security]

Are you doing it in a loop? If it is just once it will not be that bad.

[deleted for project safety; ]

I generate a GUID for every bullet I fire at around 1000 rpm for a bullet ID system and I notice no significant performance changes.

To test it out use a for loop and use os.clock to benchmark how long it takes to generate a lot of GUID or math.random code.

-- Record the initial time:
local startTime = os.clock()
-- Do something you want to measure the performance of:
local a, b = 0, 1
for i = 1, 5000000 do
    a, b = b, a
end
-- Measure amount of time this took:
local deltaTime = os.clock() - startTime
print("Elapsed time: " .. deltaTime)
-->  Elapsed time: 0.044425600033719 (actual number may vary)

I’m on mobile and I gotta sleep so I can’t test it out rn.

1 Like

Thanks, I think this put it in a clear way for me to understand. I will need to delete this post though or someone will probably manage to find out enough details to eventually compromise the project I’m working on.