import { paddingLeft } from './string' ; function randomNum ( minNum , maxNum ) { switch ( arguments . length ) { case 1 : return Math . random ( ) * minNum + 1 ; case 2 : return Math . random ( ) * ( maxNum - minNum + 1 ) + minNum ; default : return 0 ; } } example param { number } length function randomPhoneCode ( length = 6 ) { let maxNumStr = '' ; for ( let i = 0 ; i < length ; i ++ ) { maxNumStr += '9' ; } let maxNum = Number ( maxNumStr ) ; let codeNum = randomNum ( 0 , maxNum ) ; return paddingLeft ( codeNum . toString ( ) , length ) ; } export { randomNum , randomPhoneCode } ;