add function randomNumber
This commit is contained in:
		
							parent
							
								
									39173e47bb
								
							
						
					
					
						commit
						2224e9c00f
					
				
							
								
								
									
										20
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								index.js
									
									
									
									
									
								
							@ -117,6 +117,22 @@ module.exports = {
 | 
				
			|||||||
    return parseInt(port)
 | 
					    return parseInt(port)
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  randomNumber ({ length, min, max } = {}) {
 | 
				
			||||||
 | 
					    // 长度为 length 的随机数字,或者 (min||0) <= num < max
 | 
				
			||||||
 | 
					    var num = 0
 | 
				
			||||||
 | 
					    if (typeof length === 'number' && length > 0) {
 | 
				
			||||||
 | 
					      num = parseInt(Math.random() * Math.pow(10, length))
 | 
				
			||||||
 | 
					      num = num.toString().padStart(length, '0')
 | 
				
			||||||
 | 
					    } else if (typeof max === 'number' && max > 0) {
 | 
				
			||||||
 | 
					      min = typeof min === 'number' && min >= 0 ? min : 0
 | 
				
			||||||
 | 
					      num = parseInt(Math.random() * (max - min)) + min
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      // 如果 option 为空
 | 
				
			||||||
 | 
					      num = Math.random()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return num
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * 用户编号转邀请码
 | 
					   * 用户编号转邀请码
 | 
				
			||||||
   *
 | 
					   *
 | 
				
			||||||
@ -125,7 +141,7 @@ module.exports = {
 | 
				
			|||||||
   * @return {*}
 | 
					   * @return {*}
 | 
				
			||||||
   * @memberof TICrypto
 | 
					   * @memberof TICrypto
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  aiid2regcode(aiid) {
 | 
					  aiid2regcode (aiid) {
 | 
				
			||||||
    const alphabet = 'e5fcdg3hqa4b1n0pij2rstuv67mwx89klyz'
 | 
					    const alphabet = 'e5fcdg3hqa4b1n0pij2rstuv67mwx89klyz'
 | 
				
			||||||
    const base = 16367
 | 
					    const base = 16367
 | 
				
			||||||
    let num = (aiid + base) * (base - alphabet.length)
 | 
					    let num = (aiid + base) * (base - alphabet.length)
 | 
				
			||||||
@ -147,7 +163,7 @@ module.exports = {
 | 
				
			|||||||
   * @return {*}
 | 
					   * @return {*}
 | 
				
			||||||
   * @memberof TICrypto
 | 
					   * @memberof TICrypto
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  regcode2aiid(code) {
 | 
					  regcode2aiid (code) {
 | 
				
			||||||
    if (typeof code === 'string' && /^[a-zA-Z0-9]+$/.test(code)) {
 | 
					    if (typeof code === 'string' && /^[a-zA-Z0-9]+$/.test(code)) {
 | 
				
			||||||
      const alphabet = 'e5fcdg3hqa4b1n0pij2rstuv67mwx89klyz'
 | 
					      const alphabet = 'e5fcdg3hqa4b1n0pij2rstuv67mwx89klyz'
 | 
				
			||||||
      const base = 16367
 | 
					      const base = 16367
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user