Easiest way to determine if any of 6 strings match another

Trying to find an easy and clean way to find if any of 6 strings match the other 5.

I am building a table of data from a number of JSON files, and some of the data blocks are duplicated.  Not everyone might have access to all JSON files, so some data goes in different files.

I generate 6 random numbers and use those data records.  In each data block, I have a value that I don’t want to repeat.  So in my 6 blocks that I will use, none should have that field match another.  If it does, then I want to either try again, or throw out the repeat and get another.

Wanted to figure out how to do this as cleanly as possible.

Any suggestions for how to compare the 6 strings and ensure that I have 6 data blocks that each have that value as unique?

The best way to do very fast checking of strings being one of a set is to use a table, something like:

local stringList = { "fred" = 1,"jim" = 1,"bill" = 1,"kevin" = 1,"dennis" = 1 } if stringList[name] ~= nil then -- if you get here you know 'name' is not on of the keys in the table end

@paulscottrobson,

Thanks for that suggestion.  I had not thought of that and that would work well for determining duplicates.

I ended up needing to go with a different solution to make it easier to replace the duplicates.    I had not used a while loop before, and ended up doing that to achieve this when I generate the random numbers in the first place.

Appreciate your reply and will actually know someplace else I can use that. 

The best way to do very fast checking of strings being one of a set is to use a table, something like:

local stringList = { "fred" = 1,"jim" = 1,"bill" = 1,"kevin" = 1,"dennis" = 1 } if stringList[name] ~= nil then -- if you get here you know 'name' is not on of the keys in the table end

@paulscottrobson,

Thanks for that suggestion.  I had not thought of that and that would work well for determining duplicates.

I ended up needing to go with a different solution to make it easier to replace the duplicates.    I had not used a while loop before, and ended up doing that to achieve this when I generate the random numbers in the first place.

Appreciate your reply and will actually know someplace else I can use that.