Variable with random name

Post your questions and help other users.

Moderator: Martin

Post Reply
colabi
Posts: 134
Joined: 06 Jan 2013 22:33

Variable with random name

Post by colabi » 08 Jul 2015 21:41

Hi

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

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

Thanks

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Variable with random name

Post by Martin » 10 Jul 2015 08:36

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

Post Reply