当前位置:网站首页>Securerandom things | true and false random numbers
Securerandom things | true and false random numbers
2022-07-05 19:50:00 【Bulst】
The previous articles , This paper introduces several ways of generating random numbers , So what is pseudo-random number ?
So called pseudo-random numbers , It means as long as given ⼀ Initial species ⼦, production ⽣ The random number sequence of is complete ⼀ What kind of .
for (int i = 0; i < 10; i++) {
Random random = new Random(123);
int randomValue = random.nextInt(10);
System.out.println(randomValue);
}
When we initialize Random When no seed is given , The current time will be given as the seed by default .
/** * Creates a new random number generator. This constructor sets * the seed of the random number generator to a value very likely * to be distinct from any other invocation of this constructor. */
public Random() {
this(seedUniquifier() ^ System.nanoTime());
}
track
* @return the current value of the running Java Virtual Machine's
* high-resolution time source, in nanoseconds
* @since 1.5
*/
public static native long nanoTime();
that , What is a true random number ?
Real random numbers can only pass through quantities ⼦⼒ Learn principles to get ,⽽ What we want is ⼀ An unpredictable, secure random
Count ,SecureRandom Namely ⽤ To create safe random numbers :
SecureRandom sr = new SecureRandom();
System.out.println(sr.nextInt(100));
SecureRandom⽆ Cannot designate species ⼦, It makes ⽤RNG(random number generator) Algorithm .JDK Of SecureRandom There are actually many different underlying implementations , Some envoys ⽤ Safe random species ⼦ Add the pseudo-random number algorithm to produce ⽣ Safe random number , Some envoys ⽤ Real random number ⽣ Make it .
Actually make ⽤ When , Priority can be given to ⾼ Safe random number of intensity ⽣ Make it , If not provided , Then make ⽤ Ordinary level of safety random number ⽣ Make it :
import java.util.Arrays;
import java.security.SecureRandom;
import java.security.NoSuchAlgorithmException;
public class Main {
public static void main(String[] args) {
SecureRandom sr = null;
try {
// obtain ⾼ Strength safety random number ⽣ Make it
sr = SecureRandom.getInstanceStrong();
} catch (NoSuchAlgorithmException e) {
// Get ordinary safe random numbers ⽣ Make it
sr = new SecureRandom();
}
}
SecureRandom The security of is a random kind of security provided by the operating system ⼦ Come on ⽣ Into random numbers .
This species ⼦ It's through CPU The hot noise of 、 Read and write the bytes of the disk 、⽹ Network flow and other random events produce ⽣ Of “ entropy ”.
In cryptography , Safe random number ⾮ Always important . If so ⽤ Unsafe pseudo-random numbers , All encryption systems will be broken .
therefore , Always remember that you must make ⽤SecureRandom To produce ⽣ Safe random number .
边栏推荐
- 力扣 1200. 最小绝对差
- Concept and syntax of function
- 【obs】QString的UTF-8中文转换到blog打印 UTF-8 char*
- What is the function of okcc call center
- No matter how busy you are, you can't forget safety
- 建立自己的网站(16)
- Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
- third-party dynamic library (libcudnn.so) that Paddle depends on is not configured correctl
- 完爆面试官,一线互联网企业高级Android工程师面试题大全
- Necessary skills for interview in large factories, 2022android will not die, I will not fall
猜你喜欢
城链科技数字化创新战略峰会圆满召开
Successful entry into Baidu, 35K monthly salary, 2022 Android development interview answer
Postman核心功能解析-参数化和测试报告
Win10 x64环境下基于VS2017和cmake-gui配置使用zxing以及opencv,并实现data metrix码的简单检测
Android interview classic, 2022 Android interview written examination summary
Add data to excel small and medium-sized cases through poi
[Collection - industry solutions] how to build a high-performance data acceleration and data editing platform
Xaas trap: all things serve (possible) is not what it really needs
How MySQL queries and modifies JSON data
MMO項目學習一:預熱
随机推荐
Worthy of being a boss, byte Daniel spent eight months on another masterpiece
信息/数据
建立自己的网站(16)
Complete interview questions for interviewers and senior Android engineers in front-line Internet enterprises
Reptile exercises (II)
aggregate
Hiengine: comparable to the local cloud native memory database engine
Postman core function analysis - parameterization and test report
Is it safe to open a mobile stock account? Is it reliable?
third-party dynamic library (libcudnn.so) that Paddle depends on is not configured correctl
Redis cluster simulated message queue
Where is the operation of new bonds? Is it safer and more reliable to open an account
众昂矿业:2022年全球萤石行业市场供给现状分析
通配符选择器
Debezium series: record the messages parsed by debezium and the solutions after the MariaDB database deletes multiple temporary tables
40000 word Wenshuo operator new & operator delete
Win10 x64环境下基于VS2017和cmake-gui配置使用zxing以及opencv,并实现data metrix码的简单检测
线程池参数及合理设置
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
强化学习-学习笔记4 | Actor-Critic