当前位置:网站首页>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.
边栏推荐
- Audio and video development interview questions
- Spark的RDD(弹性分布式数据集)返回大结果集
- Li Kou leetcode 280 weekly match
- LeetCode 1551. Minimum operand to make all elements in the array equal
- 第5章 NameNode和SecondaryNameNode
- 图像处理一百题(11-20)
- ~71 abbreviation attribute of font
- ~86m rabbit practice
- ~70 row high
- Solr standalone installation
猜你喜欢

Chapter III principles of MapReduce framework

~74 JD top navigation bar exercise

Hbuilder x format shortcut key settings

我走过最迷的路,是字节跳动程序员的脑回路

~81 long table

Chapter 5 yarn resource scheduler

Eureka single machine construction

Solve the problem that intel12 generation core CPU single thread only runs on small cores

Spark independent cluster dynamic online and offline worker node

The 116 students spent three days reproducing the ByteDance internal real technology project
随机推荐
Double specific tyrosine phosphorylation regulated kinase 1A Industry Research Report - market status analysis and development prospect prediction
LeetCode 1552. Magnetic force between two balls
两个礼拜速成软考中级软件设计师经验
CMake速成
SQL快速入门
第三章 MapReduce框架原理
Submit several problem records of spark application (sparklauncher with cluster deploy mode)
力扣leetcode第 280 场周赛
第6章 DataNode
string. How to choose h and string and CString
Research Report on hearing health care equipment industry - market status analysis and development prospect prediction
7-7 ring the stupid bell
Basic principles of video compression coding and audio compression coding
~84 form supplement
LeetCode 1637. The widest vertical area between two points without any point
腾讯面试算法题
LeetCode 1566. Repeat the pattern with length m at least k times
Codeforces Global Round 19
Tencent interview algorithm question
Solr new core