3. JS生成32位随机数

function randomWord ( randomFlag,min,max ) {

  var str = " ",

    range = min,

    arr = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'];

  //随机产生

  if ( randomFlag ) {

    range = Math.round( Math.random( ) * ( max-min)) + min;

  }

  for ( var i=0; i<range;i++ ) {

    pos = Math.round(Math.random( ) * (arr.length-1));

    str += arr [pos]

    console.log( str )

    return str;

}

randomWord(false,32)        //220b4eac9068d368a639d62eeaf5cb59

randomWord(true,3,32)  //tesa87sd34s

posted @ 2018-02-27 10:32  大耳朵小虎  阅读(1216)  评论(0编辑  收藏  举报