当前位置:网站首页>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.
边栏推荐
- ~74 JD top navigation bar exercise
- 7-7 ring the stupid bell
- China tetrabutyl urea (TBU) market trend report, technical dynamic innovation and market forecast
- Spark独立集群Worker和Executor的概念
- ByteDance new programmer's growth secret: those glittering treasures mentors
- Codeforces Global Round 19
- 这116名学生,用3天时间复刻了字节跳动内部真实技术项目
- Tencent interview algorithm question
- Monomer application concept
- China double brightening film (dbef) market trend report, technical dynamic innovation and market forecast
猜你喜欢
Eureka single machine construction
我走過最迷的路,是字節跳動程序員的腦回路
第6章 Rebalance详解
第2章 HFDS的Shell操作
Submit several problem records of spark application (sparklauncher with cluster deploy mode)
Hbuilder x format shortcut key settings
[unsolved]7-14 calculation diagram
7-5 blessing arrived
Chapter III principles of MapReduce framework
JS encapsulates the method of array inversion -- Feng Hao's blog
随机推荐
Hbuilder x format shortcut key settings
Chapter 2 shell operation of hfds
LeetCode 1637. The widest vertical area between two points without any point
Educational Codeforces Round 122 (Rated for Div. 2)
~69 other ways to use icon fonts
字节跳动开源GAN模型压缩框架,算力最高节省97.8%丨ICCV 2021
string. How to choose h and string and CString
Tert butyl hydroquinone (TBHQ) Industry Research Report - market status analysis and development prospect forecast
[unsolved] 7-15 shout mountain
7-6 sum of combinatorial numbers
腾讯面试算法题
LeetCode 1545. Find the k-th bit in the nth binary string
Chapter 1 overview of MapReduce
The concept of spark independent cluster worker and executor
China tetrabutyl urea (TBU) market trend report, technical dynamic innovation and market forecast
~70 row high
~75 background
Spark独立集群Worker和Executor的概念
ByteDance new programmer's growth secret: those glittering treasures mentors
Chapter 6 datanode