[ WP ] Write a story in JavaScript , C # , or another computer language .

<? php 
 
 // Should generate a story in a thousand years or so. 
 
 function thousandMonkeys ( ) { 
 $ fredrickBrown = 17; 
 $ marcelProust = 1267069; 
 $ totalWords = rand ( $ fredrickBrown, $ marcelProust ); 
 $ line = ``''; 
 
 $ ascii_a = 97; 
 $ ascii_z = 122; 
 
 $ longest = strlen ( `` Pneumonoultramicroscopicsilicovolcanoconiosis'' ); // 45 
 
 $ nameFrequency = 27; // Research this 
 $ punctuationFrequency = 10; // And this 
 $ punctuation = array ( ``. ``, ``,'', ``! ``, ``? ``, `` \'''', `` `'', ``;'', ``:'' ); // Need to weight this somehow? 
 
 $ newLineFrequency = 70; 
 
 $ numWords = 0; 
 
 while ( $ numWords < = $ totalWords ) { 
 $ word = ``''; 
 while ( 1 ) { 
 $ word.= chr ( rand ( $ ascii_a, $ ascii_z ) ); 
 // Weight this towards shorter words? Tends to be lengthy. 
 if ( strlen ( $ word ) > rand ( 1, $ longest ) ) { 
 if (! $ line ) $ word = ucfirst ( $ word ); 
 if ( rand ( 0, $ nameFrequency ) == $ nameFrequency ) $ word = ucfirst ( $ word ); 
 $ line.= $ word; 
 break; 
 } 
 } 
 if ( rand ( 0, $ punctuationFrequency ) == $ punctuationFrequency ) { 
 $ line.= $ punctuation [ array_rand ( $ punctuation ) ]; 
 } 
 if ( rand ( 0, $ newLineFrequency ) == $ newLineFrequency ) { 
 if ( substr ( $ line, -1 )! = ``.'' ) $ line = trim ( $ line ).''. ``; // Is this cheating? 
 print $ line. `` \n''; 
 $ line = ``''; 
 } else { 
 $ line.= `` ``; 
 } 
 
 $ numWords++; 
 } 
 if ( $ line ) { 
 if ( substr ( $ line, -1 )! = ``.'' ) $ line = trim ( $ line ).''. ``; // Is this cheating? 
 print $ line. `` \n''; 
 } 
 } 
 
 while ( 1 ) { 
 print thousandMonkeys ( ); 
 print `` \n\n\n''; 
 print `` Another? ( Y/N ) \n''; 
 $ choice = trim ( fgets ( STDIN ) ); 
 if ( strtolower ( $ choice ) == `` n'' ) exit; 
 } 
 
? >
