SecureRandom getSeed() method in Java with Examples
The getSeed() method of java.security.SecureRandom class is used to return the given number of seed bytes, computed using the seed generation algorithm that this class uses to seed itself. This call may be used to seed other random number generators.
This method is only included for backward compatibility. The caller is encouraged to use one of the alternative getInstance methods to obtain a SecureRandom object, and then call the generateSeed method to obtain seed bytes from that object.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
public static byte getSeed(int numBytes)
Parameters: This method takes the number of seed bytes as a parameter to generate.
Return Value: This method returns the seed bytes.
Below are the examples to illustrate the getSeed() method:
Seed Bytes : [1, 2, 3, 4, 1]
Seed Bytes : [-64, 79, 82, -118, -97, -95, -80, -101, -40, 12]
- The above programs will not run on online IDE.
- Every time Secure Random class will generate random output.