public int update() {

    final double N = (double) Network.size();
    // final double m = Math.log(N)/Math.log(2.0);
    final double t = (double) ++age;

    // final double eps = c*K/(d*d*t*N*N);
    final double eps = Math.min(1.0, c * K / (d * d * t * N));
    int I = 0; // index of the arm which will be played in the current run

    if (t == 1) {
      I = CommonState.r.nextInt(GlobalArmModel.numberOfArms());
    } else {
      final double r = CommonState.r.nextDouble();
      if (r < eps) {
        // random
        I = CommonState.r.nextInt(GlobalArmModel.numberOfArms());
      } else {
        // best
        I = bestArmIdx();
      }
    }

    // play arm I
    final double xi = GlobalArmModel.playMachine(I);

    // update
    if (Utils.isPower2(t)) {
      addAndSetTo0(s, r);
      addAndSetTo0(w, q);
      addAndSetTo0(r, f);
      addAndSetTo0(q, g);
    }
    final double mul = N / 2.0;
    f[I] += mul * xi;
    g[I] += mul;

    // update counters
    n[I]++;
    sumN++;

    return I;
  }