Programming

(Javascript) Random Text

steloflute 2012. 7. 30. 13:13

var randomText = function() {
    var r = "";
    var firstChar = true;
    for (var i=0; i<1000; i++) {
     var c = String.fromCharCode(Math.floor(Math.random() * 26) + "a".charCodeAt(0));
     if (firstChar) {
      c = c.toUpperCase();
      firstChar = false;
     }
     r += c;
     if (Math.random() < 0.20) {
      if (Math.random() < 0.20) {
       r += ". ";
       firstChar = true;
      }
      else
       r += " ";
     }
    }
    return r;
}

randomText()

'Programming' 카테고리의 다른 글

3 ways to define a JavaScript class  (0) 2012.08.05
The Need For One True Coding Style  (0) 2012.08.02
JavaScript Popup Boxes  (0) 2012.07.27
Are functional languages inherently slow?  (0) 2012.07.27
jquery test  (0) 2012.07.26