Page 1 of 1

Variable with random name

Posted: 08 Jul 2015 21:41
by colabi
Hi

Is possible to create a variable with a random number in name?
Something like:

xxx = random(100, 999);
global_variable_xxx = value;

Thanks

Re: Variable with random name

Posted: 10 Jul 2015 08:36
by Martin
Hi,

You can use function setValue to achieve this.
For example:

Code: Select all

setValue("global_variable_"+random(1, 100), value);
However I would recommend not to use this mechanism but insterad use a map to store random values:

Code: Select all

global_map_with_random_values = newMap();
addMapEntry(global_map_with_random_values, "key_"+random(1, 100), value);
value = getMapValue(global_map_with_random_values, "key_"+random(1, 100));
The advatage is that you only have one global variable that groups all your values.

Regards,
Martin