made with requirebin
Created
March 15, 2016 09:56
-
-
Save kentaromiura/a753aeaeb01a7387880b to your computer and use it in GitHub Desktop.
requirebin sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// require() some stuff from npm (like you were using browserify) | |
// and then hit Run Code to run it on the right | |
var twister = require('mersenne-twister') | |
var generator = new twister(); | |
function rand(max, modifier) { | |
modifier = modifier || 0; | |
var rnd = generator.random_incl(); | |
return modifier + 1 + Math.round(rnd * max); | |
} | |
var d20 = rand.bind(null, 19); | |
var d4 = rand.bind(null, 3); | |
var d8 = rand.bind(null, 7); | |
var d6 = rand.bind(null, 5); | |
var d10 = rand.bind(null, 9); | |
var d12 = rand.bind(null, 11); | |
var d100 = rand.bind(null, 99); | |
window.d4 = d4; | |
window.d6 = d6; | |
window.d8 = d8; | |
window.d10 = d10; | |
window.d12 = d12; | |
window.d20 = d20; | |
window.d100 = d100; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({"mersenne-twister":[function(require,module,exports){var MersenneTwister=function(seed){if(seed==undefined){seed=(new Date).getTime()}this.N=624;this.M=397;this.MATRIX_A=2567483615;this.UPPER_MASK=2147483648;this.LOWER_MASK=2147483647;this.mt=new Array(this.N);this.mti=this.N+1;this.init_seed(seed)};MersenneTwister.prototype.init_seed=function(s){this.mt[0]=s>>>0;for(this.mti=1;this.mti<this.N;this.mti++){var s=this.mt[this.mti-1]^this.mt[this.mti-1]>>>30;this.mt[this.mti]=(((s&4294901760)>>>16)*1812433253<<16)+(s&65535)*1812433253+this.mti;this.mt[this.mti]>>>=0}};MersenneTwister.prototype.init_by_array=function(init_key,key_length){var i,j,k;this.init_seed(19650218);i=1;j=0;k=this.N>key_length?this.N:key_length;for(;k;k--){var s=this.mt[i-1]^this.mt[i-1]>>>30;this.mt[i]=(this.mt[i]^(((s&4294901760)>>>16)*1664525<<16)+(s&65535)*1664525)+init_key[j]+j;this.mt[i]>>>=0;i++;j++;if(i>=this.N){this.mt[0]=this.mt[this.N-1];i=1}if(j>=key_length)j=0}for(k=this.N-1;k;k--){var s=this.mt[i-1]^this.mt[i-1]>>>30;this.mt[i]=(this.mt[i]^(((s&4294901760)>>>16)*1566083941<<16)+(s&65535)*1566083941)-i;this.mt[i]>>>=0;i++;if(i>=this.N){this.mt[0]=this.mt[this.N-1];i=1}}this.mt[0]=2147483648};MersenneTwister.prototype.random_int=function(){var y;var mag01=new Array(0,this.MATRIX_A);if(this.mti>=this.N){var kk;if(this.mti==this.N+1)this.init_seed(5489);for(kk=0;kk<this.N-this.M;kk++){y=this.mt[kk]&this.UPPER_MASK|this.mt[kk+1]&this.LOWER_MASK;this.mt[kk]=this.mt[kk+this.M]^y>>>1^mag01[y&1]}for(;kk<this.N-1;kk++){y=this.mt[kk]&this.UPPER_MASK|this.mt[kk+1]&this.LOWER_MASK;this.mt[kk]=this.mt[kk+(this.M-this.N)]^y>>>1^mag01[y&1]}y=this.mt[this.N-1]&this.UPPER_MASK|this.mt[0]&this.LOWER_MASK;this.mt[this.N-1]=this.mt[this.M-1]^y>>>1^mag01[y&1];this.mti=0}y=this.mt[this.mti++];y^=y>>>11;y^=y<<7&2636928640;y^=y<<15&4022730752;y^=y>>>18;return y>>>0};MersenneTwister.prototype.random_int31=function(){return this.random_int()>>>1};MersenneTwister.prototype.random_incl=function(){return this.random_int()*(1/4294967295)};MersenneTwister.prototype.random=function(){return this.random_int()*(1/4294967296)};MersenneTwister.prototype.random_excl=function(){return(this.random_int()+.5)*(1/4294967296)};MersenneTwister.prototype.random_long=function(){var a=this.random_int()>>>5,b=this.random_int()>>>6;return(a*67108864+b)*(1/9007199254740992)};module.exports=MersenneTwister},{}]},{},[]);var twister=require("mersenne-twister");var generator=new twister;function rand(max,modifier){modifier=modifier||0;var rnd=generator.random_incl();return modifier+1+Math.round(rnd*max)}var d20=rand.bind(null,19);var d4=rand.bind(null,3);var d8=rand.bind(null,7);var d6=rand.bind(null,5);var d10=rand.bind(null,9);var d12=rand.bind(null,11);var d100=rand.bind(null,99);window.d4=d4;window.d6=d6;window.d8=d8;window.d10=d10;window.d12=d12;window.d20=d20;window.d100=d100; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "requirebin-sketch", | |
"version": "1.0.0", | |
"dependencies": { | |
"mersenne-twister": "1.0.1" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- contents of this file will be placed inside the <body> --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- contents of this file will be placed inside the <head> --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment