How to Secure Strong Random Numbers in Java


In this example we will show the method to create strong random numbers in Java.

Source Code

package com.beginner.examples;

import java.security.SecureRandom;

public class StrongRandomExample {

    public static void main(String[] args){
    	SecureRandom random = new SecureRandom();    	
    	int num = 4;
    	while(num>0)
    	{
    		Integer randNum = random.nextInt(100);
    		System.out.println(randNum.toString());
    		num--;
    	}
    }
}

Output:

4
49
16
3

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments