Pipe - Text Function to Generate Random Text

If this exists I can’t find it :slight_smile: so I thought I’d drop it here for feedback…perhaps I’ve missed something :thinking:

I need to create a random string of characters from a reduced set of characters. For argument sake lets say I want to limit the characters to “12345QWERTY”

So I know I could create a TB Javaside script called from a Pipe and I’m probably going down that route but it would be nice if this was a was on API calls included in the Tadabase Text Utilities pipe. There is already something similar the “Password Phase Generator” which creates a random phrase but this would be a little different.

There could be two parameter:
Length of String = 10
Available characters = 12345QWERTY

Result Example: 44W21TR42Q

This would be really useful for generating pins for SMS resets, passwords and in my case just a long random filename for AWS file storage.

[I’m currently performing this function in MAKE but it’s really inefficient as it users 40+ “operations” (and this is their suggested method!)]

I created this pipe if anyone else finds it useful it’s here, works well for me :slight_smile:

newstring =“”;
for (let i = 1; i <= {length}; i++) {
randnum = Math.floor(Math.random() * “{characters}”.length);
newchar = “{characters}”.substring(randnum ,randnum +1);
newstring =newstring+newchar
}



1 Like

@GREDDIE
Does this feature still work? I copied it my own app, but I can’t get it to work. The response is the there is an invalid key.

@slimpens looks like a couple of lines are missing in the request. Try this:

newstring = “”;
length = parseInt(“{length}”);
chars = “{characters}”;

for (let i = 1; i <= length; i++) {
randnum = Math.floor(Math.random() * chars.length);
newchar = chars.substring(randnum, randnum + 1);
newstring = newstring + newchar;
}

Hi @slimpens yes it works it’s just the quote symbol got changed in the paste into the blog system it should be : …

var newstring = "";
for (var i = 1; i <= {length}; i++) {
randnum = Math.floor(Math.random() * "{characters}".length);
newchar = "{characters}".substring(randnum, randnum + 1);
newstring = newstring + newchar;
}

Just retested and this example above is working :+1:

1 Like

Thank you it works!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.