startv

Ecpxa

A Pen By Martin

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource
via CSS Lint

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource
via JS Hint

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Want a Run Button?

If active, the preview will update automatically when you change code.

HTML

            
              <button onclick='GENERATE()'>GENERATE</button>
<textarea cols="30" rows="10" class="code"></textarea>

<p class='explanation'>Clicking the generate button generates random WORKING JavaScript code. Every time you click, more (working) code gets appended. 
  <br>It's 100% pseudorandom (as random as the Math.random() function). It's.. the worst thing I ever did.
<br>The box displays generated JS code.
<br>Fun fact: Statistically, it's possible that this code becomes skynet.
    <br>Fun fact #2: Statistically, it's possible that this code creates itself.
    <br>Fun fact #3: Statistically, it's possible that this code creates a 100% accurate picture of YOU.
    <br>Fun fact #4: Statistically, it's possible that this code solves all unsolved mathematical, scientifical, biological, statistical, philosophical and even more problems.
  <br> Fun fact #5: Statistically, it's more likely to generate something that makes no sense at all, and it will probably hang after about 7 clicks on the generate button.
</p>
            
          
!

CSS

            
              
            
          
!

JS

            
              // Clicking the generate button generates WORKING Javascript code... It's 100% pseudorandom (as random as the Math.random() function). It's.. the worst thing I ever did.
// The box displays generated JS code.
// Fun fact: Statistically, it's possible that this code becomes skynet.
var allowed_characters = 
    ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '-', '*', '\\', "'", '"', '=', '<', '>', '.', ',', '|', '%', '&', '^', '~', '!', '#', '$', '{', '}', '(', ')', '[', ']', ':', ';', '\n', ' '];
var code = '';
var last_added = '';

function choice(arr) {
  index = Math.floor(Math.random() * arr.length);
  return arr[index];
}

function run_code () {
  try {
    eval(code);
    return true;
  } catch (e) {
    return false;
  }
}

function add_code () {
  var amount = Math.random() * 25,
      new_code = '';
  for (var i = 0; i < amount; i += 1) {
    new_code += choice(allowed_characters);
  }
  code += new_code;
  last_added = new_code;
}

function fix_code () {
  remove_last_added();
  add_code();
}

function remove_last_added () {
  code = code.substring(0, code.length - last_added.length);
}

function GENERATE () {
  var iterations = 0;
  add_code();
  while(!run_code()) {
    iterations += 1;
    fix_code();
    if (iterations >= 10000) {
      alert('Sorry, the code hangs a little, I\'ve made sure your browser doesn\'t crash :) (the code won\'t be errorless now though :<)');
      remove_last_added();
      break;
    }
  }
  $('.code').val(code);
}
            
          
!
999px
Loading ..................

Console