首页 > 编程语言 >JavaSE---Random

JavaSE---Random

时间:2024-02-18 16:01:19浏览次数:29  
标签:util use code java Random --- JavaSE class

java.util.Random

概述

An instance of this class is used to generate a stream of pseudorandom numbers. 

Random实例用来 生成伪随机数 ;

The class uses a 48-bit seed, which is modified using a linear congruential formula. (See Donald Knuth,The Art of Computer Programming, Volume 2</i>, Section 3.2.1.)

使用48位的seed,

 

If two instances of {@code Random} are created with the same seed, and the same sequence of method calls is made for each, they will generate and return identical sequences of numbers.
In order to guarantee this property, particular algorithms are specified for the class {@code Random}.
Java implementations must use all the algorithms shown here for the class {@code Random}, for the sake of absolute portability of Java code.
However, subclasses of class {@code Random} are permitted to use other algorithms, so long as they adhere to the general contracts for all the methods.

 

The algorithms implemented by class {@code Random} use a {@code protected} utility method that on each invocation can supply up to 32 pseudorandomly generated bits.

Random实现的算法 使用protected方法(每次调用时可以提供最多32个伪随机生成的位)

Many applications will find the method {@link Math#random} simpler to use. 

Math的random是更简易使用的;
Instances of {@code java.util.Random} are threadsafe.

Random 是线程安全的;
However, the concurrent use of the same {@code java.util.Random} instance across threads may encounter contention and consequent poor performance.

跨线程并发使用同一个Random实例,可能会遇到争用,导致性能不佳;
Consider instead using {@link java.util.concurrent.ThreadLocalRandom} in multithreaded designs.

多线程中可以使用java.util.concurrent.ThreadLocalRandom

 

Instances of {@code java.util.Random} are not cryptographically secure.

Random实例 是加密不安全的;
Consider instead using {@link java.security.SecureRandom} to get a cryptographically secure pseudo-random number generator for use by security-sensitive applications.

可以使用SecureRandom获取加密安全的伪随机数生成器

 

标签:util,use,code,java,Random,---,JavaSE,class
From: https://www.cnblogs.com/anpeiyong/p/18019434

相关文章

  • 2024-02-17-物联网C语言(5-指针)
    5.指针5.1关于内存那点事存储器:外存和内存 外存:长期存放数据,掉电不会丢失数据,如硬盘、光盘、ROM等 内存:暂时存放数据,掉电数据丢失,如RAM,DDR等内存:物理内存和虚拟内存物理内存:实实在在的存储设备虚拟内存:操作系统虚拟出来的内存操作系统会在物理内存和虚拟内存之间做映......
  • [刷题笔记] P9751 [CSP-J 2023] 旅游巴士
    Problem_LinkDescription给定一个\(n\)个点,\(m\)条边的有向图。起点为\(1\),终点为\(n\)。起始时间和终止时间必须是\(k\)的倍数。通过每条边的时间为\(1\)。每条边有限制\(a_i\)即若通过当前边必须满足当前时间\(t\geqa_i\)。求满足上述限制的前提下,到达终点的最小......
  • Go-embed把静态文件打包到二进制
    同级目录建立view文件夹。packagemainimport( "bytes" "embed" "encoding/json" "fmt" "github.com/gin-gonic/gin" "html/template" "io/ioutil" "net/http")const( gptUrl......
  • Random
    maven<!--https://mvnrepository.com/artifact/org.apache.commons/commons-lang3--><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.9</version>......
  • 23-06知识积累
    序号知识点描述 分析频繁FGC问题 堆内存使用过高:https://buzkgep88z.feishu.cn/docx/IW2YdwtOAoGKSDxbgoKcmsH5nvhmat使用说明:JVM系列之:MAT工具使用教程-掘金(juejin.cn)使用教程:(43封私信/80条消息)结合MAT分析OOM问题(视频版)-知乎(zhihu.com)......
  • 初中英语优秀范文100篇-083My Low-carbon Life-我的低碳生活
    PDF格式公众号回复关键字:SHCZFW083记忆树1Theenvironmentalpollutionisworseandworsetoday.翻译今天的环境污染越来越严重简化记忆污染句子结构主语Theenvironmentalpollution这是句子的主要讨论对象,指的是“环境污染”。谓语is连接主语和表语,表示主......
  • node文件操作 -- 基础
    constfs=require("fs");写入-----------------------------------------------------------------//异步写入//writeFile也可以追加写入,在回调函数之前增加{flag:'a'}即可。//fs.writeFile("./texx.txt","实验操作",(err)=>{// if(err)thr......
  • RK3568驱动指南|驱动基础进阶篇-进阶6 内核运行ko文件实验——系统调用
    瑞芯微RK3568芯片是一款定位中高端的通用型SOC,采用22nm制程工艺,搭载一颗四核Cortex-A55处理器和MaliG522EE图形处理器。RK3568支持4K解码和1080P编码,支持SATA/PCIE/USB3.0外围接口。RK3568内置独立NPU,可用于轻量级人工智能应用。RK3568支持安卓11和linux系统,主要面向......
  • Day-2
    栈,队列P6033操作:找min,删min,插入必须线性复杂度**特殊的性质:每次插入的元素单调递增**,即b单调两个队列:初始的a,合并后的b,都是有序的对a排序时使用桶排序(快排太慢)总共合并n-1次,每次$O(1)$P2827如果蚯蚓长度不变->普通的优先队列(太慢)......
  • Day-3
    Dfs序CF383C简化:子树加,子树和(线段树+Dfs序)考虑对树做一个奇偶的分层x的深度为奇数,x子树中,深度为奇数+,深度为偶数-BZOJ3306小技巧:换根,Dfs序现在的根为x,原来的为rty在x的子树内->无影响y在x到根路径上->影响其他无影响if(Lca(x,......