当前位置:网站首页>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.
边栏推荐
- 【锟斤拷】的故事:谈谈汉字编码和常用字符集
- Hbuilder x format shortcut key settings
- LeetCode 1637. The widest vertical area between two points without any point
- Audio and video development interview questions
- LeetCode 1566. Repeat the pattern with length m at least k times
- Tert butyl hydroquinone (TBHQ) Industry Research Report - market status analysis and development prospect forecast
- LeetCode 1640. Can I connect to form an array
- Log statistics (double pointer)
- Usage of insert() in vector
- 我走过最迷的路,是字节跳动程序员的脑回路
猜你喜欢
LeetCode 1637. The widest vertical area between two points without any point
Spark独立集群Worker和Executor的概念
7-5 blessing arrived
音视频开发面试题
LeetCode 1557. The minimum number of points that can reach all points
~82 style of table
One hundred questions of image processing (1-10)
7-4 harmonic average
解决Intel12代酷睿CPU【小核载满,大核围观】的问题(WIN11)
~68 Icon Font introduction
随机推荐
Simply try the new amp model of deepfacelab (deepfake)
Business system compatible database oracle/postgresql (opengauss) /mysql Trivia
string. How to choose h and string and CString
Tert butyl hydroquinone (TBHQ) Industry Research Report - market status analysis and development prospect forecast
LeetCode 1551. Minimum operand to make all elements in the array equal
7-12 inventory code base
Chapter 6 datanode
~78 radial gradient
Cartesian tree (modified)
ByteDance new programmer's growth secret: those glittering treasures mentors
LeetCode 1552. Magnetic force between two balls
字节跳动多篇论文入选 CVPR 2021,精选干货都在这里了
Monomer application concept
视频压缩编码和音频压缩编码基本原理
LeetCode 1637. The widest vertical area between two points without any point
Soft music -js find the number of times that character appears in the string - Feng Hao's blog
Codeforces Global Round 19
~79 Movie card exercise
~86m rabbit practice
Li Kou leetcode 280 weekly match