当前位置:网站首页>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.
边栏推荐
- Research Report of desktop clinical chemical analyzer industry - market status analysis and development prospect prediction
- Error: case label `15 'not within a switch statement
- 我在字节跳动「修电影」
- Record the error reason
- (lightoj - 1349) Aladdin and the optimal invitation (greed)
- CMake Error: Could not create named generator Visual Studio 16 2019解决方法
- ~87 animation
- Gridhome, a static site generator that novices must know
- Market trend report, technological innovation and market forecast of double door and multi door refrigerators in China
- Spark independent cluster dynamic online and offline worker node
猜你喜欢
Chapter III principles of MapReduce framework
Audio and video development interview questions
7-4 harmonic average
Chapter 2 shell operation of hfds
Two weeks' experience of intermediate software designer in the crash soft exam
100张图训练1小时,照片风格随意变,文末有Demo试玩|SIGGRAPH 2021
第5章 NameNode和SecondaryNameNode
~82 style of table
7-5 blessing arrived
Usage of insert() in vector
随机推荐
Codeforces Round #771 (Div. 2)
LeetCode 1566. Repeat the pattern with length m at least k times
Research Report on market supply and demand and strategy of China's four flat leadless (QFN) packaging industry
Chapter 2 shell operation of hfds
~69 other ways to use icon fonts
Basic principles of video compression coding and audio compression coding
Bisphenol based CE Resin Industry Research Report - market status analysis and development prospect forecast
Redis standalone startup
Sublime text code formatting operation
ffmpeg命令行使用
~86m rabbit practice
Summary of game theory
7-12 inventory code base
Eureka high availability
Native JS realizes the functions of all selection and inverse selection -- Feng Hao's blog
The most lost road I have ever walked through is the brain circuit of ByteDance programmers
Spark independent cluster dynamic online and offline worker node
LeetCode 1561. The maximum number of coins you can get
第6章 DataNode
CMake速成