benchmark/code/for.js
function randomatic(pattern, length, options) {
  if (typeof pattern === 'undefined') {
    throw new Error('randomatic expects a string or number.');
  }

  var custom = false;
  if (arguments.length === 1) {
    if (typeof pattern === 'string') {
      length = pattern.length;

    } else if (isNumber(pattern)) {
      options = {};
      length = pattern;
      pattern = '*';
    }
  }

  if(typeOf(length) === 'object' && length.hasOwnProperty('chars')) {
    options = length;
    pattern = options.chars;
    length = pattern.length;
    custom = true;
  }

  var opts = options || {};
  var mask = '';
  var res = '';

  // Characters to be used
  if (pattern.indexOf('?') !== -1) mask += opts.chars;
  if (pattern.indexOf('a') !== -1) mask += type.lower;
  if (pattern.indexOf('A') !== -1) mask += type.upper;
  if (pattern.indexOf('0') !== -1) mask += type.number;
  if (pattern.indexOf('!') !== -1) mask += type.special;
  if (pattern.indexOf('*') !== -1) mask += type.all;
  if (custom) mask += pattern;

  for (var i = 0; i < length; i++) {
    res += mask.charAt(parseInt(Math.random() * mask.length));
  }

  return res;
}
function randomatic(pattern, length, options) {
  if (typeof pattern === 'undefined') {
    throw new Error('randomatic expects a string or number.');
  }

  var custom = false;
  if (arguments.length === 1) {
    if (typeof pattern === 'string') {
      length = pattern.length;

    } else if (isNumber(pattern)) {
      options = {};
      length = pattern;
      pattern = '*';
    }
  }

  if(typeOf(length) === 'object' && length.hasOwnProperty('chars')) {
    options = length;
    pattern = options.chars;
    length = pattern.length;
    custom = true;
  }

  var opts = options || {};
  var mask = '';
  var res = '';

  // Characters to be used
  if (pattern.indexOf('?') !== -1) mask += opts.chars;
  if (pattern.indexOf('a') !== -1) mask += type.lower;
  if (pattern.indexOf('A') !== -1) mask += type.upper;
  if (pattern.indexOf('0') !== -1) mask += type.number;
  if (pattern.indexOf('!') !== -1) mask += type.special;
  if (pattern.indexOf('*') !== -1) mask += type.all;
  if (custom) mask += pattern;

  for (var i = 0; i < length; i++) {
    res += mask.charAt(parseInt(Math.random() * mask.length));
  }

  return res;
}
function randomatic ( pattern , length , options ) { if ( typeof pattern === 'undefined' ) { throw new Error ( 'randomatic expects a string or number.' ) ; } var custom = false ; if ( arguments . length === 1 ) { if ( typeof pattern === 'string' ) { length = pattern . length ; } else if ( isNumber ( pattern ) ) { options = { } ; length = pattern ; pattern = '*' ; } } if ( typeOf ( length ) === 'object' && length . hasOwnProperty ( 'chars' ) ) { options = length ; pattern = options . chars ; length = pattern . length ; custom = true ; } var opts = options || { } ; var mask = '' ; var res = '' ; // Characters to be used if ( pattern . indexOf ( '?' ) !== - 1 ) mask += opts . chars ; if ( pattern . indexOf ( 'a' ) !== - 1 ) mask += type . lower ; if ( pattern . indexOf ( 'A' ) !== - 1 ) mask += type . upper ; if ( pattern . indexOf ( '0' ) !== - 1 ) mask += type . number ; if ( pattern . indexOf ( '!' ) !== - 1 ) mask += type . special ; if ( pattern . indexOf ( '*' ) !== - 1 ) mask += type . all ; if ( custom ) mask += pattern ; for ( var i = 0 ; i < length ; i ++ ) { res += mask . charAt ( parseInt ( Math . random ( ) * mask . length ) ) ; } return res ; }
Generate random character sequences of a specified `length`,
based on the given `pattern`.

@param {String} `pattern` The pattern to use for generating the random string.
@param {String} `length` The length of the string to generate.
@param {String} `options`
@return {String}
@api public
Generate random character sequences of a specified length based on the given pattern .