// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.security.SecureRandom;
import java.util.Random;

public class RandomSpeed {
    private static final int BUFSIZ = 32;
    private static final int N = 10000000;
    private static void prng() {
        long t1 = System.currentTimeMillis();
        Random rng = new Random();
        byte[] buf = new byte[BUFSIZ];
        for(int i = 0; i < N; i++) {
            rng.nextBytes(buf);
        }
        long t2 = System.currentTimeMillis();
        System.out.println(t2 - t1);
    }
    private static void csprng() {
        long t1 = System.currentTimeMillis();
        SecureRandom rng = new SecureRandom();
        byte[] buf = new byte[BUFSIZ];
        for(int i = 0; i < N; i++) {
            rng.nextBytes(buf);
        }
        long t2 = System.currentTimeMillis();
        System.out.println(t2 - t1);
    }
    private static void csprngx() {
        long t1 = System.currentTimeMillis();
        byte[] buf = new byte[BUFSIZ];
        for(int i = 0; i < N; i++) {
            SecureRandom rng = new SecureRandom();
            rng.nextBytes(buf);
        }
        long t2 = System.currentTimeMillis();
        System.out.println(t2 - t1);
    }
    public static void main(String[] args) {
        prng();
        csprng();
        csprngx();
    }
}
