Should I replace math.random with a pregenerated table?

Hi folks,

when I create a particle effect in my script, I use around 30 math.random calls during a frame.
This brings down the framerate (deltatime=99 … 10 FPS). My idea is now to pregenerate a table with random values and read values from there. Did someone tried this already and can confirm a performance boost could it have no effect.

Cheers
Michael [import]uid: 5712 topic_id: 746 reply_id: 300746[/import]

If it’s really that slow, we need to look into that. [import]uid: 54 topic_id: 746 reply_id: 1501[/import]

Well, I just look into it again. I don’t call just 30 times, it is 120 times I just noticed!!!

30 particles with 4 calls for x and y target position, the time for the transition and one for the scale of the particle. I think I go with a precalculated table and see how that works. [import]uid: 5712 topic_id: 746 reply_id: 1505[/import]

Ok. Lookups are always faster and if you have a large enough pre-calculated table, it won’t be noticeable. [import]uid: 54 topic_id: 746 reply_id: 1506[/import]