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