Creating cover traffic by calling random urls - Javascript loop to decrement float This is a for-loop which runs once for each step with i&gt;1 and maybe for 0 &lt;= i &lt;= 1.
var i;
var prob_ = 3.5;
for ( i = prob_; i &gt;= 0; i -= 1 ) {
    if ( i &gt; 1 || withProbability(i) ) {
        loadHttp(randomUrl());
    }
}

with
function withProbability(chance) {
    return Math.random() &lt; chance;
}

JsLint gave me a for-loop error. Is this code ok despite that warning, or should this for-loop be changed to some other looping construct?
Background
prob_ is a ratio between fake actions and real actions. The loop is triggered once for each real action. If prob_ is greater than 1, the fake action is done. If it is in between 0 and 1, it is considered a probability and thus maybe a fake action follows.
This is a case where it was not clear how to replace the for-loop with a forEach, as is often recommended. Maybe ES6 tail recursion could be used...
More context
function loadHttp(toLoad) {
    require(&quot;sdk/page-worker&quot;).Page({
        contentURL: toLoad
    });
}

The implementation of randomUrl() is rather lengthy and does not relate to the question. It determines a statistically probable length of a HTML (or embedded object like js, img, css, ...) site, then does a lookup for the next bigger URL in a hardcoded list. It is supposed that the randomness will confuse someone who watches for traffic patterns.
Full class coverTraffic.js
This is initialized via
const coverTraffic = require('./coverTraffic.js');
coverTraffic.setLoader(require('./load.js'));

with load.js containing similar to loadHttp as above. It is triggered via
function loads(URL) {
    if ( _.contains(activeHosts, URL.host) ) { // has already started
        coverTraffic.loadNext();
    } else {
        activeHosts.push(URL.host);
        coverTraffic.start();
    }
}
exports.loads = URL =&gt; loads(URL);

which is called whenever the browser loads a new URL.
&quot;use strict&quot;;

exports.DOC = 'creates cover traffic, up to predetermined parameters';

const { setTimeout } = require(&quot;sdk/timers&quot;);

const coverUrl = require(&quot;./coverUrl.js&quot;);
const stats = require(&quot;./stats.js&quot;);

/** overhead of dummy traffic -1; 1.5 has overhead of 50% */
const FACTOR = 1.5;

var load;

var site_ = {};
var pad_ = {};
var prob_;

function setLoader(load_param) {
    load = load_param;
}
exports.setLoader = (load_param) =&gt; setLoader(load_param);

/** a website is loaded by the user. covertraffic determines a target
 * feature vector and adds to the load to approximate the target.
 */
function start() {
    site_ = {};
    pad_ = {};

    site_.html = stats.htmlSize(1); // td: buffer known sites in bloomfilter
    pad_.html = stats.htmlSize(FACTOR) - site_.html;
    site_.num_embedded = stats.numberEmbeddedObjects(1); // td: see above
    pad_.num_embedded = stats.numberEmbeddedObjects(FACTOR) - site_.num_embedded;
    prob_ = pad_.num_embedded / site_.num_embedded;

    //    setTimeout(loadNext, stats.parsingTime());
    load.http(coverUrl.sized(pad_.html));
}
exports.start = start;

function loadNext() {
    var i;
    if ( pad_.num_embedded &gt; 0 ) {
    for ( i = prob_; i &gt;= 0; i -= 1 ) {
        if ( i &gt; 1 || stats.withProbability(i) ) {
        load.http(coverUrl.sized(stats.embeddedObjectSize()));
        pad_.num_embedded -= 1;
        }
    }
    } else {
    console.log(&quot;cover traffic empty, num: &quot; + pad_.num_embedded);
    }
}
exports.loadNext = loadNext;

The stats module provides statistical distributions, the load-module just loading a URL as described above.
The problem JSLint is pointing at is that you usually iterate with an index that is an integer. If you were to have an array, you couldn't use i to access the array elements, because if i is big enough, rounding issues may cause you to skip elements or see elements twice!

What I'd recommend is that you just use i as integer, and then once the for loop is done, check if there is an additional chance to roll for. That way, you don't have to worry about floating point rounding errors accumulating.

Another way you could do it is first roll, and then if you roll high enough, up i by 1. That way you only have one place where you run your code.

So like this:

var chance = i % 1;
if (chance !== 0 &amp;&amp; withProbability(chance)){
    i = Math.ceil(i);
} else {
    i = Math.floor(i);
}
//for loop goes here