javascript - Get random expression generator -


i have function creates random integers trying refactor create random addition expressions instead. it's still generating single integers. consumer needs log sum of random expressions producers making. it's work off of old github. https://github.com/ajlopez/simplequeue/blob/master/samples/producerconsumer/app.js

var sq = require('../..');  function getrandominteger(from, to) {     return + math.floor(math.random()*(to-from)); }  function producer(queue, name) {     var n = 0;     var self = this;      this.process = function() {         console.log(name + ' generates ' + n);         var msg = n;         n++;         queue.putmessage(msg);         settimeout(self.process, getrandominteger(500, 1000));     } } //this should log  //producer generates 5 + 9 //second producer generates 12 + 8    function consumer(queue, name) {     var n = 0;     var self = this;      this.process = function() {         var msg = queue.getmessagesync();          if (msg != null)             console.log(name + ' process ' + msg);          settimeout(self.process, getrandominteger(300, 600));     } } //this should log sum of 2 producers random expressions ie:  //consumer process 5 + 9 = 14 //consumer process 12 + 8 = 20  var producer = new producer(queue, 'producer'); var producer2 = new producer(queue, 'second producer'); var consumer = new consumer(queue, 'consumer'); 

this produce result string expression, numbers between 500 , 1000:

function rand(min, max){    return math.floor(math.random() * (max - min + 1)) + min;  }    function getrandomexpression(from, to){    var = rand(from, to), b = - a;    return + " + " + b  }    var expr = getrandomexpression(500, 1000);    //    document.queryselector("pre").innerhtml = json.stringify(expr);
<pre></pre>


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

spring cloud - How to configure SpringCloud Eureka instance to point to https on non standard port -

javascript - Bootstrap Popover: iOS Safari strange behaviour -