Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoder support for random bytes #24

Merged
merged 3 commits into from Apr 23, 2014
Merged

Encoder support for random bytes #24

merged 3 commits into from Apr 23, 2014

Conversation

abstractj
Copy link
Contributor

Good morning, I've added supported for encoders because not everyone speaks binary :)

Also, the Random class was renamed to avoid confusion with other APIs. SecureRandom was changed to static, because Java is a beast to collect entropy. Is not something to affect mobile devices, but speaking about servers like UPS, this might slow down the server.

If you want to test it, just run the following code:

public class Test {

    public static void main(String[] args) throws NoSuchAlgorithmException {
        int i = 0;
        long startTime = System.currentTimeMillis();
        while (i < 100000) {
            RandomUtils.randomBytes();
            i++;
        }
        long endTime = System.currentTimeMillis();
        System.out.println("#1 Total execution time: " + (endTime-startTime) + "ms");

        System.out.println("=====");

        int x = 0;
        long startTimeX = System.currentTimeMillis();
        while (x < 100000) {
            SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
            byte[] buffer = new byte[16];
            secureRandom.nextBytes(buffer);
            x++;
        }
        long endTimeX = System.currentTimeMillis();
        System.out.println("#2 Total execution time: " + (endTimeX-startTimeX) + "ms");
    }
}

@danielpassos
Copy link
Contributor

👍

@danielpassos danielpassos merged commit f6c360c into aerogear-attic:master Apr 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants