ReblogMachine.endless_summer#choice

http://reblog.machine.mamemomonga.com/js/ReblogMachine.js から。
endless summer のために random な post_id を生成する部分。

choice: function () {
  for (var a = this.range.latest - this.range.oldest, b = [], c = 1; c <= 100; c++) b.push(Math.floor(a / 100 * c));
  a = [];
  for (c = 0; c <= 50; c++) for (var d = 0; d <= 5; d++) a.push(d);
  for (c = 0; c <= 10; c++) for (d = 6; d <= 10; d++) a.push(d);
  for (c = 10; c <= 100; c++) a.push(c);
  c = Math.floor(Math.random() * a.length);
  d = Math.floor(Math.random() * b[a[c]]) + this.range.oldest;
  console.log([d, b[a[c]] + this.range.oldest, a[c]]);
  return d
}

this.range.latest が最新の post_id で、 this.range.oldest が最古の post_id 。
ユーザー数がどんどん増えているから post 間の post_id 間隔(?)がだんだん増えていっているからそのまま Math.random() しても、新しい方の post ばかりヒットしてしまう問題がある。
だから重み付けをしているらしい。

choice: function () {
  for (var a = this.range.latest - this.range.oldest, b = [], c = 1; c <= 100; c++) {
      b.push(Math.floor(a / 100 * c));
  }
  a = [];
  for (c = 0; c <= 50; c++) {
      for (var d = 0; d <= 5; d++) {
          a.push(d);
      }
  }
  for (c = 0; c <= 10; c++) {
      for (d = 6; d <= 10; d++) {
          a.push(d);
      }
  }
  for (c = 10; c <= 100; c++) {
      a.push(c);
  }
  c = Math.floor(Math.random() * a.length);
  d = Math.floor(Math.random() * b[a[c]]) + this.range.oldest;
  console.log([d, b[a[c]] + this.range.oldest, a[c]]);
  return d;
}