package mypackage;
import java.security.SecureRandom;
import java.util.Random;
public class SecureRandomTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		SecureRandom sr1 = new SecureRandom();
		System.out.println("1. SecureRandom object 1. nextInt() result :" + sr1.nextInt());
		System.out.println("1. SecureRandom object 2. nextInt() result :" + sr1.nextInt());
		System.out.println("1. SecureRandom object 3. nextInt() result :" + sr1.nextInt());
		System.out.println("1. SecureRandom object 4. nextInt() result :" + sr1.nextInt());
		System.out.println("1. SecureRandom object 5. nextInt() result :" + sr1.nextInt()+"\n\n\n");
		SecureRandom sr2 = new SecureRandom();
		System.out.println("2. SecureRandom object 1.nextInt() result :" + sr2.nextInt()+"\n\n\n");
		Random r1 = new Random();
		System.out.println("1. Random object 1. nextInt() result :" + r1.nextInt());
		System.out.println("1. Random object 2. nextInt() result :" + r1.nextInt()+"\n\n\n");
		Random r2 = new Random();
		System.out.println("2. Random object 1. nextInt() result :" + r2.nextInt());
	}

}

The output is :

1. SecureRandom object 1. nextInt() result :2081492090
1. SecureRandom object 2. nextInt() result :1073396477
1. SecureRandom object 3. nextInt() result :134130488
1. SecureRandom object 4. nextInt() result :-1229020596
1. SecureRandom object 5. nextInt() result :-679432773

2. SecureRandom object 1.nextInt() result :1924631447

1. Random object 1. nextInt() result :1121875770
1. Random object 2. nextInt() result :-486804200

2. Random object 1. nextInt() result :1910565042


So what is the difference? I can't see any difference between these two...

Recommended Answers

All 2 Replies

Isn't API explanation of Random and SecureRandom enough for you?

Isn't API explanation of Random and SecureRandom enough for you?

Sadly no :(

I'm sorry for asking such a question like this. But i wanted a clear explanation from a person who has good and deep knowledge about this topic.

Sorry again for asking :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.