当前位置:网站首页>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.
边栏推荐
- 视频压缩编码和音频压缩编码基本原理
- Record the error reason: terminate called after throwing an instance
- LeetCode 1637. The widest vertical area between two points without any point
- ~71 abbreviation attribute of font
- Erlang installation
- Chapter 5 namenode and secondarynamenode
- 字节跳动新程序员成长秘诀:那些闪闪发光的宝藏mentor们
- Soft music -js find the number of times that character appears in the string - Feng Hao's blog
- Eureka high availability
- Ffmpeg command line use
猜你喜欢
Basic principles of video compression coding and audio compression coding
Mp4 format details
Sublime text code formatting operation
LeetCode 1637. The widest vertical area between two points without any point
解决Intel12代酷睿CPU【小核载满,大核围观】的问题(WIN11)
Eureka single machine construction
Spark独立集群动态上线下线Worker节点
Submit several problem records of spark application (sparklauncher with cluster deploy mode)
One hundred questions of image processing (11-20)
Ffmpeg command line use
随机推荐
~84 form supplement
Tencent interview algorithm question
Use JQ to realize the reverse selection of all and no selection at all - Feng Hao's blog
LeetCode 1637. The widest vertical area between two points without any point
~85 transition
Spark独立集群Worker和Executor的概念
LeetCode 1636. Sort the array in ascending order by frequency
Log statistics (double pointer)
Bisphenol based CE Resin Industry Research Report - market status analysis and development prospect forecast
~79 Movie card exercise
我在字节跳动「修电影」
Continue and break jump out of multiple loops
CMake速成
CMake Error: Could not create named generator Visual Studio 16 2019解决方法
Codeforces Global Round 19
图像处理一百题(1-10)
The concept of spark independent cluster worker and executor
Simple records of business system migration from Oracle to opengauss database
7-7 ring the stupid bell
Native JS realizes the functions of all selection and inverse selection -- Feng Hao's blog