character function

2
Hi everyone, In order to generate a password, I want to add a random number to a character. e.g. $Add = floor ( Random() * 26). Suppose the result of this is 9. I want to add 9 to 'a' with 'k' as a result. When I say $String = 'a' + $Add, the result is 'a9' How can resolve this? Thanks Erik
asked
4 answers
2

You could also use a microflow that generates an random string based on an input string that specifies all allowed characters and an int that defines how long the result should be.

Edit: You might also want to add a validation check to ensure that the random part does not become 1. Otherwise you could end up with an index out of bound or something like that.

then you do something like:

$index = round(random()*length($allowedChars))
$result = $result+substring($allowedChars,$index,1)

length($result) = $length
if true quit microflow and return result, if false loop back to the start and result will append to itself.
answered
1

Note that the community commons module contains a randomString function that creates alphanumeric random strings of a specified length.

answered
0

Create a java action to get a random number and return it as a string, like:

...
       import java.util.Random;
...

        // BEGIN USER CODE
        Random randomGenerator = new Random();
        int randomInt = randomGenerator.nextInt(100);
        String tmpNbr = Integer.toString(randomInt);
        return tmpNbr;
        // END USER CODE

The code above will return a random number between 0 and 99 as a text string that you can then concatenate with your text using a simple change action.

answered
0

Use an Enum with the number to character translation.

This also allows you to use Uppercase and (to some extend) special character results.

answered