packages/optimizely-sdk/lib/core/bucketer/index.js
function(bucketingKey) {
    try {
      // NOTE: the mmh library already does cast the hash value as an unsigned 32bit int
      // https://github.com/perezd/node-murmurhash/blob/master/murmurhash.js#L115
      var hashValue = murmurhash.v3(bucketingKey, HASH_SEED);
      var ratio = hashValue / MAX_HASH_VALUE;
      return parseInt(ratio * MAX_TRAFFIC_VALUE, 10);
    } catch (ex) {
      throw new Error(sprintf(ERROR_MESSAGES.INVALID_BUCKETING_ID, MODULE_NAME, bucketingKey, ex.message));
    }
  }
function(bucketingKey) {
    try {
      // NOTE: the mmh library already does cast the hash value as an unsigned 32bit int
      // https://github.com/perezd/node-murmurhash/blob/master/murmurhash.js#L115
      var hashValue = murmurhash.v3(bucketingKey, HASH_SEED);
      var ratio = hashValue / MAX_HASH_VALUE;
      return parseInt(ratio * MAX_TRAFFIC_VALUE, 10);
    } catch (ex) {
      throw new Error(sprintf(ERROR_MESSAGES.INVALID_BUCKETING_ID, MODULE_NAME, bucketingKey, ex.message));
    }
  }
function ( bucketingKey ) { try { // NOTE: the mmh library already does cast the hash value as an unsigned 32bit int // https://github.com/perezd/node-murmurhash/blob/master/murmurhash.js#L115 var hashValue = murmurhash . v3 ( bucketingKey , HASH_SEED ) ; var ratio = hashValue / MAX_HASH_VALUE ; return parseInt ( ratio * MAX_TRAFFIC_VALUE , 10 ) ; } catch ( ex ) { throw new Error ( sprintf ( ERROR_MESSAGES . INVALID_BUCKETING_ID , MODULE_NAME , bucketingKey , ex . message ) ) ; } }
Helper function to generate bucket value in half-closed interval [0, MAX_TRAFFIC_VALUE)
@param  {string} bucketingKey String value for bucketing
@return {string} the generated bucket value
@throws If bucketing value is not a valid string
Helper function to generate bucket value in half - closed interval [ 0 MAX_TRAFFIC_VALUE )