当前位置:网站首页>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 .
边栏推荐
- Summer Challenge database Xueba notes, quick review of exams / interviews~
- Debezium series: record the messages parsed by debezium and the solutions after the MariaDB database deletes multiple temporary tables
- Where is the operation of new bonds? Is it safer and more reliable to open an account
- The city chain technology Digital Innovation Strategy Summit was successfully held
- 建议收藏,我的腾讯Android面试经历分享
- Worthy of being a boss, byte Daniel spent eight months on another masterpiece
- How to safely and quickly migrate from CentOS to openeuler
- 多分支结构
- Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
- [OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*
猜你喜欢
[untitled]
如何在2022年更明智地应用智能合约?
Django uses mysqlclient service to connect and write to the database
40000 word Wenshuo operator new & operator delete
Add data to excel small and medium-sized cases through poi
Microwave radar induction module technology, real-time intelligent detection of human existence, static micro motion and static perception
不愧是大佬,字节大牛耗时八个月又一力作
Summer Challenge database Xueba notes, quick review of exams / interviews~
[hard core dry goods] which company is better in data analysis? Choose pandas or SQL
XaaS 陷阱:万物皆服务(可能)并不是IT真正需要的东西
随机推荐
Summer Challenge database Xueba notes, quick review of exams / interviews~
挖财钱堂教育靠谱安全吗?
How to safely and quickly migrate from CentOS to openeuler
redis集群模拟消息队列
The difference between ID selector and class selector
深度學習 卷積神經網絡(CNN)基礎
S7-200smart uses V90 Modbus communication control library to control the specific methods and steps of V90 servo
Bitcoinwin (BCW)受邀参加Hanoi Traders Fair 2022
城链科技数字化创新战略峰会圆满召开
再忙不能忘安全
Base du réseau neuronal de convolution d'apprentissage profond (CNN)
Is it safe to open a mobile stock account? Is it reliable?
Hiengine: comparable to the local cloud native memory database engine
Android interview, Android audio and video development
C#应用程序界面开发基础——窗体控制(6)——菜单栏、工具栏和状态栏控件
PG basics -- Logical Structure Management (user and permission management)
shell编程基础(第9篇:循环)
安信证券在网上开户安全吗?
微波雷达感应模块技术,实时智能检测人体存在,静止微小动静感知
third-party dynamic library (libcudnn.so) that Paddle depends on is not configured correctl