<commit_before>var querystring = require('querystring');
var http = require('http');
var fs = require('fs');
var crypto = require('crypto');

function getResult(options, callback) {
    options = options || {};
    
    var dlkbpsRange = {max : 1999999, min : 1};
    var ulkbpsRange = {max : 1999999, min : 1};
    var pingmsRange = {max : 65535, min : 0};
    
    var dlkbps = isPositive(options.download) ? Math.floor(options.download) : 200000;
    var ulkbps = isPositive(options.upload) ? Math.floor(options.upload) : 200000;
    var pingms = isPositive(options.ping) ? Math.floor(options.ping) : 40;
    var srv = isPositive(options.server) ? options.server : 5056;
    
    if (!options.noRandomize) {
        dlkbps = randomize(dlkbps);
        pingms = randomize(pingms);
        ulkbps = randomize(ulkbps);
    }
    
    dlkbps = fixRange(dlkbps, dlkbpsRange);
    ulkbps = fixRange(ulkbps, ulkbpsRange);
    pingms = fixRange(pingms, pingmsRange);
    
    function isPositive(val) {
        return typeof val === "number" && isFinite(val) && val >= 0;
    }
    
    function fixRange(val, limit) {
        if (val > limit.max) {
            return limit.max;
        }
        if (val < limit.min) {
            return limit.min;
        }
        return val;
    }
    
    function hash(parameters, algorithm, seperator) {
        seperator = seperator || "-";
        algorithm = algorithm || "md5"; 
        var str = parameters.join(seperator);
        var shasum = crypto.createHash(algorithm);
        shasum.update(encodeURIComponent(str));
        return shasum.digest('hex');
    }

    function randomize(number) {
        return Math.floor(number * (0.8 + 0.2 * Math.random()));
    }
    
    function parse(res) {
        var i, tempArr, tempArr2, id, resObj;
        res = res.toString();
        tempArr = res.split('&');
        resObj = {};
        for (i = tempArr.length - 1; i >= 0; i--) {
            tempArr2 = tempArr[i].split("=");
            resObj[decodeURIComponent(tempArr2[0])] = decodeURIComponent(tempArr2[1]);
        }
        resObj.resultURL = "http://www.speedtest.net/my-result/" + resObj.resultid;
        resObj.resultImage = "http://www.speedtest.net/result/" + resObj.resultid + ".png";
        return resObj;
    }
    
    // Build the post string from an object
    var post_data = querystring.stringify({
        "download" : dlkbps,
        'ping' : pingms,
        'upload' : ulkbps,
        'promo' : "",
        'startmode' : 'pingselect',<commit_msg>change randomize range for different  parameter<commit_after>var querystring = require('querystring');
var http = require('http');
var fs = require('fs');
var crypto = require('crypto');

function getResult(options, callback) {
    options = options || {};
    
    var dlkbpsRandomizeRange = {max : 1, min : 0.8};
    var ulkbpsRandomizeRange = {max : 1, min : 0.8};
    var pingmsRandomizeRange = {max : 1.2, min : 0.8};
    
    var dlkbpsRange = {max : 1999999, min : 1};
    var ulkbpsRange = {max : 1999999, min : 1};
    var pingmsRange = {max : 65535, min : 0};
    
    
    var dlkbps = isPositive(options.download) ? Math.floor(options.download) : 200000;
    var ulkbps = isPositive(options.upload) ? Math.floor(options.upload) : 200000;
    var pingms = isPositive(options.ping) ? Math.floor(options.ping) : 40;
    var srv = isPositive(options.server) ? options.server : 5056;
    
    if (!options.noRandomize) {
        dlkbps = randomize(dlkbps, dlkbpsRandomizeRange);
        ulkbps = randomize(ulkbps, ulkbpsRandomizeRange);
        pingms = randomize(pingms, pingmsRandomizeRange);
    }
    
    dlkbps = fixRange(dlkbps, dlkbpsRange);
    ulkbps = fixRange(ulkbps, ulkbpsRange);
    pingms = fixRange(pingms, pingmsRange);
    
    function isPositive(val) {
        return typeof val === "number" && isFinite(val) && val >= 0;
    }
    
    function fixRange(val, limit) {
        if (val > limit.max) {
            return limit.max;
        }
        if (val < limit.min) {
            return limit.min;
        }
        return val;
    }
    
    function hash(parameters, algorithm, seperator) {
        seperator = seperator || "-";
        algorithm = algorithm || "md5"; 
        var str = parameters.join(seperator);
        var shasum = crypto.createHash(algorithm);
        shasum.update(encodeURIComponent(str));
        return shasum.digest('hex');
    }

    function randomize(number, range) {
        return Math.floor(number * (range.min + (range.max - range.min) * Math.random()));
    }
    
    function parse(res) {
        var i, tempArr, tempArr2, id, resObj;
        res = res.toString();
        tempArr = res.split('&');
        resObj = {};
        for (i = tempArr.length - 1; i >= 0; i--) {
            tempArr2 = tempArr[i].split("=");
            resObj[decodeURIComponent(tempArr2[0])] = decodeURIComponent(tempArr2[1]);
        }
        resObj.resultURL = "http://www.speedtest.net/my-result/" + resObj.resultid;
        resObj.resultImage = "http://www.speedtest.net/result/" + resObj.resultid + ".png";
        return resObj;
    }
    
    // Build the post string from an object
    var post_data = querystring.stringify({
        "download" : dlkbps,
        'ping' : pingms,
        'upload' : ulkbps,
        'promo' : "",
        'startmode' : 'pingselect',
{'fraction_non_alphanumeric': 0.13951310861423222, 'fraction_numerical': 0.021348314606741574, 'mean_word_length': 2.3975826972010177, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2793403', 'n_tokens_mistral': 1829, 'n_tokens_neox': 1727, 'n_words': 373}