当前位置:网站首页>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 .
边栏推荐
- Build your own website (16)
- Is it safe for Guohai Securities to open an account online?
- 司空见惯 - 英雄扫雷鼠
- Win10 x64环境下基于VS2017和cmake-gui配置使用zxing以及opencv,并实现data metrix码的简单检测
- MMO project learning 1: preheating
- Concept and syntax of function
- 四万字长文说operator new & operator delete
- What does software testing do? What are the requirements for learning?
- Android interview, Android audio and video development
- Tasks in GStreamer
猜你喜欢
How about testing outsourcing companies?
建议收藏,我的腾讯Android面试经历分享
What do software test engineers do? How about the prospect of treatment?
城链科技数字化创新战略峰会圆满召开
Django uses mysqlclient service to connect and write to the database
PHP uses ueditor to upload pictures and add watermarks
Xaas trap: all things serve (possible) is not what it really needs
Recommended collection, my Tencent Android interview experience sharing
Hiengine: comparable to the local cloud native memory database engine
Millimeter wave radar human body sensor, intelligent perception of static presence, human presence detection application
随机推荐
[Collection - industry solutions] how to build a high-performance data acceleration and data editing platform
Complete interview questions for interviewers and senior Android engineers in front-line Internet enterprises
Force buckle 1200 Minimum absolute difference
常用运算符与运算符优先级
Gstreamer中的task
国信证券在网上开户安全吗?
Using repositoryprovider to simplify the value passing of parent-child components
Postman核心功能解析-参数化和测试报告
IBM大面积辞退40岁+的员工,掌握这十个搜索技巧让你的工作效率至上提高十倍
Android面试,android音视频开发
通配符选择器
打新债在哪里操作开户是更安全可靠的呢
【C语言】字符串函数及模拟实现strlen&&strcpy&&strcat&&strcmp
95后阿里P7晒出工资单:狠补了这个,真香...
Reinforcement learning - learning notes 4 | actor critical
C#应用程序界面开发基础——窗体控制(5)——分组类控件
Apprentissage du projet MMO I: préchauffage
大厂面试必备技能,2022Android不死我不倒
Millimeter wave radar human body sensor, intelligent perception of static presence, human presence detection application
Fundamentals of shell programming (Part 8: branch statements -case in)