当前位置:网站首页>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 .
边栏推荐
- 面试官:Redis中集合数据类型的内部实现方式是什么?
- Reflection and imagination on the notation like tool
- 软件测试是干什么的?学习有啥要求?
- 国海证券在网上开户安全吗?
- Fundamentals of shell programming (Part 8: branch statements -case in)
- 什么是面上项目
- 众昂矿业:2022年全球萤石行业市场供给现状分析
- Microwave radar induction module technology, real-time intelligent detection of human existence, static micro motion and static perception
- 使用easyexcel模板导出的两个坑(Map空数据列错乱和不支持嵌套对象)
- 测试的核心价值到底是什么?
猜你喜欢
![[C language] string function and Simulation Implementation strlen & strcpy & strcat & StrCmp](/img/32/738df44b6005fd84b4a9037464e61e.jpg)
[C language] string function and Simulation Implementation strlen & strcpy & strcat & StrCmp

【合集- 行业解决方案】如何搭建高性能的数据加速与数据编排平台

Bitcoinwin (BCW)受邀参加Hanoi Traders Fair 2022

JVMRandom不可设置种子|问题追溯|源码追溯

使用easyexcel模板导出的两个坑(Map空数据列错乱和不支持嵌套对象)

Force buckle 1200 Minimum absolute difference

Redis cluster simulated message queue

Reinforcement learning - learning notes 4 | actor critical

Bitcoinwin (BCW) was invited to attend Hanoi traders fair 2022

建立自己的网站(16)
随机推荐
Analysis of openh264 decoded data flow
建立自己的网站(16)
S7-200SMART利用V90 MODBUS通信控制库控制V90伺服的具体方法和步骤
Float.floatToRawIntBits的返回值具体意思,将float转为byte数组
Necessary skills for interview in large factories, 2022android will not die, I will not fall
力扣 729. 我的日程安排表 I
ACM getting started Day1
函数的概念及语法
Android面试,android音视频开发
The relationship between temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
95后阿里P7晒出工资单:狠补了这个,真香...
Force buckle 729 My schedule I
How about testing outsourcing companies?
Fundamentals of shell programming (Chapter 9: loop)
国信证券在网上开户安全吗?
What are general items
Interviewer: what is the internal implementation of set data types in redis?
城链科技数字化创新战略峰会圆满召开
完爆面试官,一线互联网企业高级Android工程师面试题大全
[AI framework basic technology] automatic derivation mechanism (autograd)