6 ms·
I created a Markov chain generator: https://gist.github.com/grant/561834963dc526495c45 https://gist.github.com/grant/561834963dc526495c45 var numNodes=10;var r
by granttimmerman 12y ago
I created a Markov chain generator: https://gist.github.com/grant/561834963dc526495c45 https://gist.github.com/grant/561834963dc526495c45
var numNodes=10;var roundNum=100;var a=[];for(var i=0;i<numNodes;++i){var connections=[];var sum=0;for(var j=0;j<numNodes;++j){var randNum=Math.random()/numNodes;randNum=Math.round(randNumroundNum)/roundNum;connections[j]=randNum;sum+=randNum}connections=connections.map(function(e){var t=e(1/sum);t=Math.round(troundNum)/roundNum;return t});sum=connections.reduce(function(e,t){return e+t});connections[numNodes-1]+=1-sum;connections[numNodes-1]=Math.round(connections[numNodes-1]roundNum)/roundNum;a[i]=connections}console.log(JSON.stringify(a))
Copy and paste the output into the side bar.
- vicapow 12y agoNice!
- TazeTSchnitzel 12y agoPlease indent each line with a double space so it's properly monospace formatted.
- chatmasta 12y agoYeah, your comment breaks the readability of this comment thread on my mobile (as in, everything is horrible stretched horizontally).