Fetch unique 3 character code

Certified Associate Developer

How to create list of unique 3 character alphabet code. If i pass "AAA" and 2, it should return "AAB", "AAC". 2 unique codes after "AAA"

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Random != Unique.

    Very curious as to why you would need to do this but here is some code to generate a string variable length with random characters. Not unique though. You should look into UUIDs if you want to achieve this.

    a!localVariables(
      local!character: "A",
      local!numberOfCharactersToAppend: 2,
      local!allCharacters: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
      local!charactersToAppend: a!forEach(
        items: enumerate(local!numberOfCharactersToAppend),
        expression: a!localVariables(
          local!randomIndex: rounddown((rand() * 26 + 1), 0),
          mid(
            local!allCharacters,
            local!randomIndex,
            1
          )
        )
      ),
      concat(
        local!character,
        joinarray(local!charactersToAppend, "")
      )
    )

Reply
  • 0
    Certified Lead Developer

    Random != Unique.

    Very curious as to why you would need to do this but here is some code to generate a string variable length with random characters. Not unique though. You should look into UUIDs if you want to achieve this.

    a!localVariables(
      local!character: "A",
      local!numberOfCharactersToAppend: 2,
      local!allCharacters: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
      local!charactersToAppend: a!forEach(
        items: enumerate(local!numberOfCharactersToAppend),
        expression: a!localVariables(
          local!randomIndex: rounddown((rand() * 26 + 1), 0),
          mid(
            local!allCharacters,
            local!randomIndex,
            1
          )
        )
      ),
      concat(
        local!character,
        joinarray(local!charactersToAppend, "")
      )
    )

Children