CommandHelper

CommandHelper

46.5k Downloads

srand()

LadyCailinBot opened this issue ยท 6 comments

commented

CMDHELPER-3006 - Reported by PseudoKnight

I'd love to do some seed randomization.

commented

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?

commented

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.

commented

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.

commented

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.

commented

Comment by PseudoKnight

I forgot about resources. That will be replaced by objects, right?

commented

Comment by LadyCailin

Yes, so don't expect this code to work forever, because I intend on basically hard deprecating it once objects exist.