LilasCorner / jlootbox

Other
1 stars 0 forks source link

Random number generator in LootBox should be static #1

Closed JohnTMurphy-NIU closed 2 years ago

JohnTMurphy-NIU commented 2 years ago

The current implementation is inefficient because every LootBox instance creates a new instance of the random number generator, which is an expensive operation; instead, make the instance of the random number generator static, so that it is shared by all instances of the class, and there will be only one created.

Note: This will work fine in the current code by just adding the 'static' keyword to the declaration of the variable, but if the random number generator is ever parameterized, you will want to create an 'init()' function to rebuild the random number generator using the parameters for that run, and then call this init() method during the builder method of the JLootBoxBuilder class.

LilasCorner commented 2 years ago

Thank you for the advice :) The latest push to develop has this implementation both for the Lootbox, and Player's random number generators.

JohnTMurphy-NIU commented 2 years ago

Great! I've closed the issue.