当前位置:网站首页>How to generate six digit verification code
How to generate six digit verification code
2022-07-06 16:49:00 【Daily enlightenment】
Method 1 :
String code = (Math.random()+"").substring(2,8)
Low efficiency .
Method 2 :
String code = String.valueOf((int)((Math.random()*9+1)*Math.pow(10,5)));
Math.pow(x,y): Calculation x Of y Power .
Math.pow(10,5):100000
Math.random()*9:0-9( barring 9)
Math.random()*9+1:1-10 ( barring 10)
Math.random()*9+1)*Math.pow(10,5):100000-1000000 ( barring 1000000)
More efficient , Because the number operation is faster than the string operation .
Wrong way :
String code = String.valueOf(new Random().nextInt(1000000));
Random().nextInt(1000000): The randomly generated number is in 0-1000000 Between , barring 1000000.
边栏推荐
- 图像处理一百题(11-20)
- (multiple methods, need to continue to see) 7-11 go deep into the tiger's Den
- 我在字节跳动「修电影」
- Business system compatible database oracle/postgresql (opengauss) /mysql Trivia
- Usage of insert() in vector
- 字节跳动新程序员成长秘诀:那些闪闪发光的宝藏mentor们
- 第6章 Rebalance详解
- Research Report on market supply and demand and strategy of China's tetraacetylethylenediamine (TAED) industry
- 解决Intel12代酷睿CPU单线程调度问题(二)
- Two weeks' experience of intermediate software designer in the crash soft exam
猜你喜欢
随机推荐
Market trend report, technical innovation and market forecast of tabletop dishwashers in China
Soft music -js find the number of times that character appears in the string - Feng Hao's blog
Research Report on market supply and demand and strategy of China's tetraacetylethylenediamine (TAED) industry
7-7 ring the stupid bell
字节跳动新程序员成长秘诀:那些闪闪发光的宝藏mentor们
解决Intel12代酷睿CPU【小核载满,大核围观】的问题(WIN11)
Ffmpeg command line use
第6章 DataNode
Research Report on market supply and demand and strategy of Chinese table lamp industry
这116名学生,用3天时间复刻了字节跳动内部真实技术项目
Tert butyl hydroquinone (TBHQ) Industry Research Report - market status analysis and development prospect forecast
LeetCode1556. Thousand separated number
~85 transition
7-8 likes (need to continue to improve)
LeetCode 1558. Get the minimum number of function calls of the target array
Jedis
~86m rabbit practice
Monomer application concept
Gridhome, a static site generator that novices must know
Spark的RDD(弹性分布式数据集)返回大结果集









