I created a function that does this work, however, I advise you to test and optimize it before applying it to a real case, especially when the string is too large. I would do this on the server-side and send the processed string to the client-side.
See:
function dividirStrPor(str, caractereDivisao, pedacos)
{
var tam = str.length;
for (var i = 0; i < pedacos; i++)
{
posicao = Math.floor(Math.random() * (tam - 0 + 1) + 0);
str = str.slice(0, posicao) + caractereDivisao + str.slice(posicao);
}
return str;
}
var str = "Deliciosogostoeobomgostodasnuvensseremfeitasdealgodao";
var resultado = dividirStrPor(str, " ", 12);
console.log(resultado);
Output:
The output changes each call of the function, due to the random position in which the division character is inserted into the string.
See working at repl.it .
Sources:
JavaScript: How can I insert a string at a specific index
Generate random number between two numbers in JavaScript