Skip to content

Instantly share code, notes, and snippets.

@nitaku
Last active January 2, 2016 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nitaku/8270950 to your computer and use it in GitHub Desktop.
Save nitaku/8270950 to your computer and use it in GitHub Desktop.
Random pronounceable strings

This example uses a predefined syllabary to produce random pronounceable strings. Reload to create new strings.

window.main = () ->
syllables = ['bi','bo','bu','ta','se','tri','su','ke','ka','flo','ko','pi','pe','no','go','zo','fu','fo','si','pa','ar','es','i','kya','kyu','fle','o','ne','na','le','lu','ma','an']
randlen = () -> 2+Math.floor(Math.random()*4)
randsy = () -> syllables[Math.floor(Math.random()*syllables.length)]
body = d3.select('body')
for i in [0...11]
body.append('div')
.text((randsy() for j in [0...randlen()]).join(''))
body {
margin-top: 40px;
margin-left: 60px;
}
div {
text-transform: capitalize;
font-size: 22pt;
color: #333333;
margin-bottom: 4px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Random names</title>
<link type="text/css" href="index.css" rel="stylesheet"/>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="index.js"></script>
</head>
<body onload="main()">
</body>
</html>
(function() {
window.main = function() {
var body, i, j, randlen, randsy, syllables, _results;
syllables = ['bi', 'bo', 'bu', 'ta', 'se', 'tri', 'su', 'ke', 'ka', 'flo', 'ko', 'pi', 'pe', 'no', 'go', 'zo', 'fu', 'fo', 'si', 'pa', 'ar', 'es', 'i', 'kya', 'kyu', 'fle', 'o', 'ne', 'na', 'le', 'lu', 'ma', 'an'];
randlen = function() {
return 2 + Math.floor(Math.random() * 4);
};
randsy = function() {
return syllables[Math.floor(Math.random() * syllables.length)];
};
body = d3.select('body');
_results = [];
for (i = 0; i < 11; i++) {
_results.push(body.append('div').text(((function() {
var _ref, _results2;
_results2 = [];
for (j = 0, _ref = randlen(); 0 <= _ref ? j < _ref : j > _ref; 0 <= _ref ? j++ : j--) {
_results2.push(randsy());
}
return _results2;
})()).join('')));
}
return _results;
};
}).call(this);
body
margin-top: 40px
margin-left: 60px
div
text-transform: capitalize
font-size: 22pt
color: #333
margin-bottom: 4px
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment