Skip to content

Instantly share code, notes, and snippets.

@ndrwhr
Created November 24, 2013 20:28
Show Gist options
  • Save ndrwhr/7632034 to your computer and use it in GitHub Desktop.
Save ndrwhr/7632034 to your computer and use it in GitHub Desktop.
var str = (function(expectedLength){
var stateMap = {
'empty': ['⦧', '⦦'],
'⦧': ['⦦', '⦢'],
'⦦': ['⦧', '⦢'],
'⦢': ['⦣'],
'⦣': ['⦧']
};
var random_ = function(arr){
return arr[Math.floor(Math.random() * arr.length)]
};
return (function FSM(output){
if (output.length === expectedLength){
return output;
} else {
var state = output.charAt(output.length - 1) || 'empty';
return FSM(output + random_(stateMap[state]));
}
})('');
})(140);
// Outputs something like:
// ⦧⦦⦢⦣⦧⦢⦣⦧⦦⦧⦢⦣⦧⦦⦢⦣⦧⦢⦣⦧⦦⦢⦣⦧⦦⦧⦦⦧⦢⦣⦧⦦⦧⦦⦢⦣⦧⦦⦧⦢⦣⦧⦢⦣⦧⦦⦧⦢⦣⦧⦦⦧⦦⦧⦦⦧⦢⦣⦧⦢⦣⦧⦢⦣⦧⦢⦣⦧⦢⦣⦧⦢⦣⦧⦢⦣⦧⦦⦧⦦⦢⦣⦧⦢⦣⦧⦢⦣⦧⦢⦣⦧⦢⦣⦧⦦⦢⦣⦧⦢⦣⦧⦦⦧⦦⦢⦣⦧⦦⦢⦣⦧⦢⦣⦧⦢⦣⦧⦢⦣⦧⦦⦢⦣⦧⦦⦢⦣⦧⦦⦧⦢⦣⦧⦢⦣⦧⦢⦣⦧
console.log(str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment