Types of Randomness

Java storage libraries Randominclude Randomand SecureRandom(and I see ThreadLocalRandom). Are there any others? When will I use each? Sometimes I use it SecureRandomjust to feel better about my primes. It turns out that SecureRandomactually allows you to choose your generator . How and when should I use this?

Finally, Java 8 provides SecureRandom.getInstanceStrong(). I'm not sure what it is, but it is much slower than any previous one. How and when should I use SecureRandom.getInstanceStrong()? Also, is it slow because the noise source is running out?

+4
source share
1 answer

Randomis predictable, you just need a small sequence of generated numbers, and you can go back and forth through the sequence. See Inverse function of a random Java function for an example of a sequence change.

SecureRandom no.

ThreadLocalRandom- an attempt to correct the fact that Randomit is not thread safe.

Other forms of randomness are possible with various functions - you will have to study the mathematics of random numbers in order to be able to balance between the ones you mentioned and any other algorithm.

SecureRandom getInstanceStrong()(note Strong ) seems to be an even stronger random sequence that is especially resistant to exhibiting long sequences.

Randomness

- , , , .

, . , , , . :

private static int lastRandom = 0;

public static int nextRandom() {
  return ++lastRandom;
}

, , , .

, StackOverflow. , , . .

, , . , .

- . , , Wikipedia, , .

+11

Source: https://habr.com/ru/post/1537582/


All Articles