Hi Team,
How to generate a unique but random words per user? Like for example, bluecarrot123, redbanana456.
But every user must have a unique random words.
Thanks in advance for help!
Hi Team,
How to generate a unique but random words per user? Like for example, bluecarrot123, redbanana456.
But every user must have a unique random words.
Thanks in advance for help!
If you want it to be unique and stable for each user, then the last number (p1) should use rowId, or you can create a stable number from a random column.
Example result: redbananadYY
function hashString(str) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
hash = (hash << 5) - hash + str.charCodeAt(i);
hash |= 0;
}
return Math.abs(hash);
}
function generateUniqueName(rowID) {
rowID = String(rowID);
const adjectives = ["blue", "red", "green", "happy", "silly"];
const nouns = ["carrot", "banana", "apple", "orange", "grape"];
const hash = hashString(rowID);
const adjective = adjectives[hash % adjectives.length];
const noun = nouns[(hash >> 2) % nouns.length];
const lastThreeChars = rowID.slice(-3);
return `${adjective}${noun}${lastThreeChars}`;
}
return generateUniqueName(p1);
this is awesome Himaladin I was just about to try this out but this is neat you could even customize this further
Thanks @Himaladin ! Is there a way to not have those words hard coded? Can it generate a word based from the row number?
You can use numbers from random columns as I mentioned. If you want row numbers, just create a row number and replace p1 with your row number column.
I have edited the script a bit to take the last 3 numbers.
Do you know how to create row numbers?
Like himaladin said you’d need to have some basic value elsewhere already… an option is to use AI to do this directly but I wouldn’t want to use it for something so generic