当前位置:网站首页>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.
边栏推荐
- 业务系统从Oracle迁移到openGauss数据库的简单记录
- ~79 Movie card exercise
- LeetCode1556. Thousand separated number
- LeetCode 1545. Find the k-th bit in the nth binary string
- 两个礼拜速成软考中级软件设计师经验
- [unsolved]7-14 calculation diagram
- 第五章 Yarn资源调度器
- LeetCode 1551. Minimum operand to make all elements in the array equal
- Market trend report, technical innovation and market forecast of China's desktop capacitance meter
- (lightoj - 1349) Aladdin and the optimal invitation (greed)
猜你喜欢
随机推荐
~75 background
7-6 sum of combinatorial numbers
LeetCode 1641. Count the number of Lexicographic vowel strings
~69 other ways to use icon fonts
LeetCode 1447. Simplest fraction
Market trend report, technical innovation and market forecast of double-sided foam tape in China
7-8 likes (need to continue to improve)
Spark independent cluster dynamic online and offline worker node
How to insert mathematical formulas in CSDN blog
第6章 Rebalance详解
音视频开发面试题
Solr standalone installation
ffmpeg命令行使用
ByteDance new programmer's growth secret: those glittering treasures mentors
~70 row high
Chapter 6 rebalance details
Codeforces Round #771 (Div. 2)
ByteDance 2022 school recruitment R & D advance approval publicity meeting, students' top 10 issues
~81 long table
Solr new core








