Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

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

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!-- 
  I'm using this to detect if this
  is the showcase pen. Other pens
  might use the ISAAC library
  in the future, then there should
  be no jQuery stuff.
-->
<div id="main-pen"></div>

<div id="container">
  <h1>ISAAC - Cryptographic Pseudo-random number generator</h1>
  <hr/>
  <div class="column">
    <h2>Input - seeds and such</h2>
    <hr />
    <div class="field">
      <label>Seed</label>
      <input type="number" name="seed" value="1337" />
      <input type="button" name="time" value="Use time" />
    </div>
    
    <div class="field">
      <label>Min/max</label>
      <input class="half" type="number" name="min" value="1" />
      <input class="half" type="number" name="max" value="100" />
    </div>
    
    <div class="field go">
      <input type="button" name="rval" value="long()" />
      <input type="button" name="rmax" value="max" />
      <input type="button" name="rmm" value="min, max" />
    </div>
    
  </div>
  <div class="column">
    <h2>Output - result and context</h2>
    <hr />
    <table>
      <tr><td>result:</td><td id="rr">Click a button!</td></tr>
      <tr><td>rctx.a:</td><td id="ra"></td></tr>
      <tr><td>rctx.b:</td><td id="rb"></td></tr>
      <tr><td>rctx.c:</td><td><span id="rc">0</span> (steps)</td></tr>
      <tr><td>rctx.cnt:</td><td><span id="rcnt">0</span> (available, auto-step at 0)</td></tr>
      
    </table>
    <input type="button" name="step" value="Step CTX and reset available count" id="stepper" />
  </div>
  
  <div class="clear"></div>
  
  <div class="column p100">
    <h2>Output - context memory and result</h2>
    <hr />
    <label for="result">Result (buffer which is regenerated each 255 long() calls)</label>
    <textarea id="result" name="rmem" readonly></textarea>
    <label for="memory">Memory (buffer used in context to calculate new result when cnt is zero)</label>
    <textarea id="memory" name="rrsl" readonly></textarea>
  </div>
  <div id="footer">
    MIT licensed, use wherever. A link back to my CodePen profile or imagine-programming.com would be appreciated. Also check out <a href="http://burtleburtle.net/bob" target="_blank">Robert J. Jenkins Jr's website</a>, the inventor of this algorithm. I wanted to make this pen after making SmallPRNG in Javascript in a similar way. <a href="https://codepen.io/ImagineProgramming/pen/bcmyD" target="_blank">Check it out!</a>
  </div>
</div>
              
            
!

CSS

              
                @mixin prefix($option, $value) {
  -webkit-#{$option}: $value;
   -khtml-#{$option}: $value;
     -moz-#{$option}: $value;
      -ms-#{$option}: $value;
       -o-#{$option}: $value;
          #{$option}: $value;
}

@mixin center-x() {
  margin-left: auto;
  margin-right: auto;
}

%clearfix {
  *zoom: 1;
  &:before, &:after {
    content: " ";
    display: table;
  }
  &:after {
    clear: both;
  }
}

*, *:before, *:after {	
  @include prefix(box-sizing, border-box);
}

body, html {
	margin: 0;
	padding: 0;
}

body {
  background: #333333;
  font-family: "Roboto", "Helvetica", sans-serif;
  font-weight: 300;
  padding: 0 10px;
}

#container {
  @include center-x();
  @include prefix(border-radius, 5px);
  @include prefix(box-shadow, 0px 7px 26px 0px rgba(30, 30, 30, 0.55));
  padding: 20px;
  background: #454545;
  width: 800px;
  color: #ffffff;
  margin-top: 10px;
  margin-bottom: 10px;
  
  @extend %clearfix;
  
  .clear {
    @extend %clearfix;
  }
  
  h1, h2 {
    margin: 0;
    padding: 0;
  }
  
  h1 {
    font-size: 1.5em;
  }
  
  h2 {
    font-size: 1.0em;
  }
  
  hr {
	border: 0;
	height: 0;
	border-top: 1px solid rgba(0, 0, 0, 0.1);
	border-bottom: 1px solid rgba(255, 255, 255, 0.3);
  }
  
  div.column {
    @include prefix(border-radius, 5px);
    @include prefix(box-shadow, 0px 7px 26px 0px rgba(30, 30, 30, 0.55));
    float: left;
    width: 49%;
    
    background: #333;
    border: #444 1px solid;
    
    padding: 5px;
    
    &:first-of-type {
      margin-right: 2%;
    }
    
    margin-bottom: 15px;
    &.p100 {
      width: 100%;
    }
  }
  
  label {
    display: block;
    font-size: 11pt;
  }
  
  #stepper {
    width: 100%;
    margin-top: 5px;
  }
  
  input, textarea {
    background: #333;
    @include prefix(border-radius, 5px);
    @include prefix(box-shadow, 0px 7px 26px 0px rgba(30, 30, 30, 0.55));
    border: #444 1px solid;
    color: #fff;
    
    padding: 3px;
    margin-bottom: 10px;
    min-height: 30px;
    
    &:focus {
      outline: 0;
    }
    
    &:hover {
      border: #888 1px solid;
      background: #444;
    }
    
    &:active {
      border: #fff 1px solid;
    }
    
    &[type="number"] {
      width: 70%;
      
      &.half {
        width: 49%;
      }
    }
    
    &[type="button"] {
      width: 28%;
    }
  }

  textarea {
    width: 100%;
    height: 100px;
  }
  
  div.go input[type="button"] {
    width: 32%;
  }
  
  &:after {
    clear: both;
    content: '';
  }
  
  table {
    width: 100%;
    border-spacing: 0px;
    border-collapse: separate;
    
    tr td:first-of-type {
      width: 100px;
    }
  }
  
  a {
    $color: #a9a9a9;
    color: $color;
    text-decoration: none;
    &:hover, &:active, &:focus {
      color: lighten($color, 20%);
    }
  }
  
  #footer {
    color: #898989;
    font-size: 10pt;
  }
}
              
            
!

JS

              
                /** 
  SmallPRNG's big brother!
  
  Not entirely finished, requires some testing, but ready for use.
  
  ISAAC library for JavaScript. Not special, 
  not optimized, not perfect. It produces
  cryptographic pseudo-random numbers by manipulating a context which was initialized 
  with or without a seed. 
  
  MIT licensed, use wherever you like, but a link
  back to my CodePen (ImagineProgramming) or website
  is appreciated (http://www.imagine-programming.com)
  
  Based on:
  http://burtleburtle.net/bob/rand/isaac.html
*/

(function(target, name) {
  if(!('Uint32Array' in window)) {
    Uint32Array = Array; // fine...
  }
  
  // maximum randval for .random([max/min [, max]])
  var RMAX = 0x7FFFFFFF;
  
  var floor = Math.floor,
      abs = Math.abs;

  var RANDSIZL = 8;
  var RANDSIZ  = (1 << RANDSIZL);

  var ISAACException = function(message) {
    this.name    = name+"Exception";
    this.message = message;
  };

  var ISAAC = function(seed) {
    this.cnt = 0;
    this.rsl = new Uint32Array(RANDSIZ);
    this.mem = new Uint32Array(RANDSIZ);
    this.a   = 0;
    this.b   = 0;
    this.c   = 0;

    // preseed the ctx if required.
    if(typeof(seed) !== "null" && typeof(seed) !== "undefined") {
      this.seed(seed);
    } else {
      this.init();
    }
  };

  var p = ISAAC.prototype;

  /**
    seed the cipher context with an array of numbers (of RANDSIZ size),
    an Uint32Array (of RANDSIZ size) or a number.
  */
  p.seed = function(seed) {
    var initFlag = false;
    // first try arrays
    if (Object.prototype.toString.call(seed) === '[object Array]') {
      for(var i = 0; i < RANDSIZ; i++) {
        this.rsl[i] = (seed[i] >>> 0) & 0xffffffff;
      }

      initFlag = true;
      // it might be a typed array
    } else if(typeof(seed) === "object" && seed instanceof Uint32Array) {
      for(var i = 0; i < RANDSIZ; i++) {
        this.rsl[i] = seed[i];
      }

      initFlag = true;
      // to hell with it, it's a number then?
    } else if (typeof(seed) === "number") {
      seed = (seed >>> 0) & 0xffffffff;
      for(var i = 0; i < RANDSIZ; i++) {
        this.rsl[i] = seed;
      }

      initFlag = true;
    } else {
      // not a valid type.
      throw new ISAACException("unknown seed type");
    }

    return this.init(initFlag);
  };

  /**
    step ciphers to the next set of pseudo-random integers.
  */
  p.step = function(times) {
    if(typeof(times) === "number") {
      for(var i = 0; i < times; i++) {
        this.step();
      }

      return;
    }

    var x, y;
    this.c++;
    this.b += this.c;

    for(var i = 0; i < RANDSIZ; ++i) {
      x = this.mem[i];
      switch(i % 4) {
        case 0: this.a = (this.a ^ (this.a << 13))>>>0; break;
        case 1: this.a = (this.a ^ (this.a >>  6))>>>0; break;
        case 2: this.a = (this.a ^ (this.a <<  2))>>>0; break;
        case 3: this.a = (this.a ^ (this.a >> 16))>>>0; break;
      }

      this.a = (this.mem[(i + 128) % RANDSIZ] + this.a)>>>0;
      this.mem[i] = y = (this.mem[(x >>> 2) % RANDSIZ] + this.a + this.b)>>>0;
      this.rsl[i] = this.b = (this.mem[(y >>> 10) % RANDSIZ] + x)>>>0;
    }
    
    this.cnt = (RANDSIZ - 1);
  };

  /**
    init initializes all the memory and values in the context and makes sure
    the first cipher step will be made. 
  */
  p.init = function(flag) {
    var a, b, c, d, e, f, g, h;   // ingredients for in our blender named mix()!
    this.a = this.b = this.c = 0; // clear a, b and c
    a=b=c=d=e=f=g=h = 0x9e3779b9; // the golden ratio

    // pfff - the blender! :)
    var mix = function() {
      a = (a ^ (b << 11)) >>> 0;
      d = (d + a) >>> 0;
      b = (b + c) >>> 0;
      b = (b ^ (c >> 2)) >>> 0;
      e = (e + b) >>> 0;
      c = (c + d) >>> 0;
      c = (c ^ (d << 8)) >>> 0;
      f = (f + c) >>> 0;
      d = (d + e) >>> 0;
      d = (d ^ (e >> 16)) >>> 0;
      g = (g + d) >>> 0;
      e = (e + f) >>> 0;
      e = (e ^ (f << 10)) >>> 0;
      h = (h + e) >>> 0;
      f = (f + g) >>> 0;
      f = (f ^ (g >> 4)) >>> 0;
      a = (a + f) >>> 0;
      g = (g + h) >>> 0;
      g = (g ^ (h << 8)) >>> 0;
      b = (b + g) >>> 0;
      h = (h + a) >>> 0;
      h = (h ^ (a >> 9)) >>> 0;
      c = (c + h) >>> 0;
      a = (a + b) >>> 0;
    };

    // scramble it
    for(var i = 0; i < 4; ++i) {
      mix();
    }

    if(flag) {
      // initialize using the contents of rsl[] as the seed
      for(var i = 0; i < RANDSIZ; i+=8) {
        a = (a + this.rsl[i  ]) >>> 0;
        b = (b + this.rsl[i+1]) >>> 0;
        c = (c + this.rsl[i+2]) >>> 0;
        d = (d + this.rsl[i+3]) >>> 0;
        e = (e + this.rsl[i+4]) >>> 0;
        f = (f + this.rsl[i+5]) >>> 0;
        g = (g + this.rsl[i+6]) >>> 0;
        h = (h + this.rsl[i+7]) >>> 0;

        mix();

        this.mem[i  ] = a;
        this.mem[i+1] = b;
        this.mem[i+2] = c;
        this.mem[i+3] = d;
        this.mem[i+4] = e;
        this.mem[i+5] = f;
        this.mem[i+6] = g;
        this.mem[i+7] = h;
      }

      // do a second pass to make all of the seed affect all of m
      for(var i = 0; i < RANDSIZ; i+=8) {
        a = (a + this.rsl[i  ]) >>> 0;
        b = (b + this.rsl[i+1]) >>> 0;
        c = (c + this.rsl[i+2]) >>> 0;
        d = (d + this.rsl[i+3]) >>> 0;
        e = (e + this.rsl[i+4]) >>> 0;
        f = (f + this.rsl[i+5]) >>> 0;
        g = (g + this.rsl[i+6]) >>> 0;
        h = (h + this.rsl[i+7]) >>> 0;

        mix();

        this.mem[i  ] = a;
        this.mem[i+1] = b;
        this.mem[i+2] = c;
        this.mem[i+3] = d;
        this.mem[i+4] = e;
        this.mem[i+5] = f;
        this.mem[i+6] = g;
        this.mem[i+7] = h;
      }
    } else {
      // fill in mem with messy stuff
      for(var i = 0; i < RANDSIZ; i+=8) {
        mix();

        this.mem[i  ] = a;
        this.mem[i+1] = b;
        this.mem[i+2] = c;
        this.mem[i+3] = d;
        this.mem[i+4] = e;
        this.mem[i+5] = f;
        this.mem[i+6] = g;
        this.mem[i+7] = h;
      }
    }

    this.step(); // fill in the first set of results
    this.cnt = RANDSIZ; // prepare to use the first set of results
  };

  /**
    pull the next 32-bit integer from the result array. If we run out of
    random data (this.cnt === 0): step the cipher for new data and reset
    the count.
  */
  p.long = function() {
    if(this.cnt-- === 0) {
      this.step();
      this.cnt = (RANDSIZ - 1); 
    }

    return this.rsl[this.cnt];
  };

  p.random = function() {
    var r = ((this.long() % RMAX) / RMAX);
    switch(arguments.length) {
        // zero arguments, return the 0-1 random factor
      case 0: {
        return r;
      } break;

        // 1 argument (max val), return random between 1 and max
      case 1: {
        var u = arguments[0];
        if(u < 1) {
          console.log("upper limit invalid");
          return null;
        }

        return (floor(r * u) + 1);

      } break;

        // 2 arguments (min, max val), return random between min and max
      case 2: {
        var l = arguments[0];
        var u = arguments[1];

        if(l >= u) {
          console.log("upper limit invalid");
          return null;
        }

        return (floor(r * (u - l + 1)) + l);
      } break;

      default: {
        console.log("invalid amount of arguments");
      } break;
    }

    return null;
  };

  target[name] = ISAAC;
  target[name+"Exception"] = ISAACException;
 
}(window, "ISAAC"));

/*
  jQuery was only used to set up a quick
  interface. Don't be mad :(
  
  This code is not required, use the lib
  above if you really really want to use
  this junk.
  
  mainPen is used to detect the showcase pen,
  future pens might refer to this one and they
  should not execute this code.
*/

var mainPen = document.getElementById("main-pen");
if(mainPen) {
  $(function() {
    var rctx = new ISAAC(1337);
    var $seedField = $('input[name="seed"]');
    var $timeSeed = $('input[name="time"]');
    var $min = $('input[name="min"]');
    var $max = $('input[name="max"]');
    var $rval = $('input[name="rval"]');
    var $rmax = $('input[name="rmax"]');
    var $rmm = $('input[name="rmm"]');
    var $stp = $('#stepper');

    var dumpCTX = function(r) {
      if(r) {
        $("#rr").text(r);
      }
      $("#ra").text(rctx.a);
      $("#rb").text(rctx.b);
      $("#rc").text(rctx.c);
      $("#rcnt").text(rctx.cnt);
      
      // dump mem and rsl
      var rsl = [];
      for(var i = 0; i < rctx.rsl.length; i++) {
        var long = rctx.rsl[i];
        var lhex = long.toString(16);
        lhex = Array(8 + 1 - lhex.length).join("0") + lhex;
        rsl.push(lhex);
      }
      $("#result").val(rsl.join(" "));
      
      var mem = [];
      for(var i = 0; i < rctx.mem.length; i++) {
        var long = rctx.mem[i];
        var lhex = long.toString(16);
        lhex = Array(8 + 1 - lhex.length).join("0") + lhex;
        mem.push(lhex);
      }
      $("#memory").val(mem.join(" "));
    };
    
    $timeSeed.click(function() {
      var time = (new Date()).getTime();
      $seedField.val(time);
      rctx = new ISAAC(+time);
      dumpCTX(rctx.long());
      return false;
    });

    $seedField.change(function() {
      rctx = new ISAAC(+$(this).val());
      dumpCTX(rctx.long());
      return false;
    });

    $rval.click(function() {
      var r = rctx.long();
      dumpCTX(r);
      return false;
    });

    $rmax.click(function() {
      var max = +$max.val();
      var r = rctx.random(max);
      dumpCTX(r);
      return false;
    });

    $rmm.click(function() {
      var min = +$min.val();
      var max = +$max.val();
      var r = rctx.random(min, max);
      dumpCTX(r);
      return false;
    });

    $stp.click(function() {
      rctx.step();
      dumpCTX();
      return false;
    });

    $rval.click();
  });  
}

              
            
!
999px

Console