0👍
✅
You can pass the replacement as a function instead of single string which will invoke for each match.
...
texts[name] = text.replace(
/./g,
() => characters.charAt(Math.floor(Math.random() * charactersLength))
)
...
Source:stackexchange.com