srand()
LadyCailinBot opened this issue ยท 6 comments
CMDHELPER-3006 - Reported by PseudoKnight
I'd love to do some seed randomization.
Comment by LadyCailin
This will probably only happen after objects. Otherwise, it would have to be a global thing. I can't think of any reasonable way to implement this otherwise. Maybe a resource temporarily?
Comment by Pieter12345
@LadyCailin A way to implement this could be by using a seed together with an index in some formulla to generate a 'random' number. The index would tell you which number is picked and could be passed to the function. That would make the format: srand(seed, index). I can imagine this isn't the greatest format to use and users could also code this in methodscript, so that's probably a reason to do what you said and wait for objects.
Comment by PseudoKnight
Ya, that's why I never PR'd my implementation. It could be stored in a map with the key being the seed, perhaps in the environment.
Comment by LadyCailin
@r = res_create_resource('RANDOM', 1);
msg(srand(@r));
msg(srand(@r));
This works as one might expect. These functions won't exist forever, but for now they will. srand
returns a double.
Comment by PseudoKnight
I forgot about resources. That will be replaced by objects, right?