lib/crypto/index.js
function rand(options) {
  options = _.opts(options, {size: 32, ascii: false, alphanumeric: false, numeric: false});
  const size = options.size;
  let data = '';
  while (data.length < size) {
    // ASCII is in range of 0 to 127
    let randBytes = crypto.pseudoRandomBytes(Math.max(size, 32)).toString();
    /* eslint-disable no-control-regex */
    if (options.ascii) randBytes = randBytes.replace(/[^\s\x00-\x7F]/g, '');
    /* eslint-enable no-control-regex */
    if (options.alphanumeric) randBytes = randBytes.replace(/[^a-zA-Z0-9]/g, '');
    if (options.numeric) randBytes = randBytes.replace(/[^0-9]/g, '');
    data += randBytes;
  }
  data = data.slice(0, size);
  return data;
}
function rand(options) {
  options = _.opts(options, {size: 32, ascii: false, alphanumeric: false, numeric: false});
  const size = options.size;
  let data = '';
  while (data.length < size) {
    // ASCII is in range of 0 to 127
    let randBytes = crypto.pseudoRandomBytes(Math.max(size, 32)).toString();
    /* eslint-disable no-control-regex */
    if (options.ascii) randBytes = randBytes.replace(/[^\s\x00-\x7F]/g, '');
    /* eslint-enable no-control-regex */
    if (options.alphanumeric) randBytes = randBytes.replace(/[^a-zA-Z0-9]/g, '');
    if (options.numeric) randBytes = randBytes.replace(/[^0-9]/g, '');
    data += randBytes;
  }
  data = data.slice(0, size);
  return data;
}
function rand ( options ) { options = _ . opts ( options , { size : 32 , ascii : false , alphanumeric : false , numeric : false } ) ; const size = options . size ; let data = '' ; while ( data . length < size ) { // ASCII is in range of 0 to 127 let randBytes = crypto . pseudoRandomBytes ( Math . max ( size , 32 ) ) . toString ( ) ; /* eslint-disable no-control-regex */ if ( options . ascii ) randBytes = randBytes . replace ( / [^\s\x00-\x7F] / g , '' ) ; /* eslint-enable no-control-regex */ if ( options . alphanumeric ) randBytes = randBytes . replace ( / [^a-zA-Z0-9] / g , '' ) ; if ( options . numeric ) randBytes = randBytes . replace ( / [^0-9] / g , '' ) ; data += randBytes ; } data = data . slice ( 0 , size ) ; return data ; }
Generate pseudo random value
@function $crypt~rand
@param {object} [options]
@param {number} [options.size=32] - Number of bytes to return
@param {boolean} [options.ascii=false] - Return ascii values
@param {boolean} [options.alphanumeric=false] - Return alphanumeric value
@param {boolean} [options.numeric=false] - Return numeric-only value
@returns {string} - Random bytes string
@example
// Generate an alphanumeric 10 chars string
$crypt.rand({'size': 10, 'alphanumeric': true});
// => 'hT8sePMvVM'
Generate pseudo random value