Created
November 24, 2013 20:28
-
-
Save ndrwhr/7632034 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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