[{"data":1,"prerenderedAt":61},["ShallowReactive",2],{"blog-post-2015-12-22-e9-9a-8f-e6-9c-ba-e6-95-b0-e6-b1-82-e5-92-8c":3},{"id":4,"title":5,"body":6,"categories":48,"date":50,"description":12,"extension":51,"meta":52,"navigation":53,"path":54,"seo":55,"stem":56,"summary":57,"tags":58,"__hash__":60},"blog\u002Fblog\u002Fe9-9a-8f-e6-9c-ba-e6-95-b0-e6-b1-82-e5-92-8c.md","随机数求和",{"type":7,"value":8,"toc":45},"minimark",[9,13,24],[10,11,12],"p",{},"题设：生成 N 个随机正整数，使他们的和等于某个数。JS 实现了一下，记录之：",[14,15,20],"pre",{"className":16,"code":18,"language":19},[17],"language-text","\u002F\u002F 绑定表单，点击后给出计算结果\ndocument.addEventListener('DOMContentLoaded', function(e){\n  var elForm = document.getElementById('form'),\n  elResult = document.getElementById('result');\n  elForm.addEventListener('submit', function(e){\n    e.preventDefault();\n    var self = this,\n    total = self\\['Total'\\].value,\n    num = self\\['Number'\\].value,\n    min = self\\['Min'\\].value,\n    app = new Random(num, total, min),\n    result = app.run();\n    elResult.innerHTML = 'Result:   \n' \\+ result.join(', ');\n  }, false);\n}, false);\n\n\u002F\u002F 计算类\nvar Random = function(num, total, min){\n  this.total = parseInt(total) || 100;\n  this.num = parseInt(num) || 1;\n  this.min = parseInt(min) || 0;\n  this.result = \\[\\];\n};\nRandom.prototype = {\n  \u002F\u002F 生成一个随机数\n  random : function(t) {\n    var max = t,\n    min = this.min;\n    return Math.floor(Math.random() * (max-min)) + min;\n  },\n  \u002F\u002F 递归计算\n  calc : function(t){\n    var self = this,\n    num = self.num,\n    min = this.min;\n    if(num * min > self.total){\n      return this.result = \\['The total number is not enough.'\\];\n    }\n    if(num === 0){\n      return false;\n    }\n    if(num === 1){\n      self.result.push(self.total);\n    }\n    if(num > 1){\n      var t =  self.total - (num-1)*min;\n      r = self.random(t),\n      self.result.push(r);\n      self.total -= r;\n    }\n    self.num--;\n    self.calc();\n  },\n  \u002F\u002F 开始计算\n  run : function(){\n    this.calc();\n    return this.result;\n  }\n};\n","text",[21,22,18],"code",{"__ignoreMap":23},"",[10,25,26,33,34,39,40],{},[27,28,32],"a",{"href":29,"rel":30},"http:\u002F\u002Fs.codepen.io\u002Finterjc\u002Fdebug\u002FrxLYjJ",[31],"nofollow","点击查看 DEMO","（",[27,35,38],{"href":36,"rel":37},"http:\u002F\u002Finterjc.github.io\u002Fcheckface\u002Fplay\u002Frandom.html",[31],"备用地址","） | ",[27,41,44],{"href":42,"rel":43},"http:\u002F\u002Fcodepen.io\u002Finterjc\u002Fpen\u002FrxLYjJ\u002F",[31],"源码调试",{"title":23,"searchDepth":46,"depth":46,"links":47},2,[],[49],"Development","2015-12-22T14:02:09+08:00","md",{},true,"\u002Fblog\u002Fe9-9a-8f-e6-9c-ba-e6-95-b0-e6-b1-82-e5-92-8c",{"title":5,"description":12},"blog\u002Fe9-9a-8f-e6-9c-ba-e6-95-b0-e6-b1-82-e5-92-8c","题设：生成 N 个随机正整数，使他们的和等于某个数。JS 实现了一下，记录之： 点击查看 DEMO（备用地址） | 源码调试",[59],"javascript","WAtHBOiy2Zp34ZkvM_88FvypjPojsLn3whev6bf6Qjs",1795177972325]