generate Random byte array - Java java.lang

Java examples for java.lang:byte Array

Description

generate Random byte array

Demo Code


//package com.java2s;
import java.security.SecureRandom;

public class Main {
    public static void main(String[] argv) throws Exception {
        int size = 2;
        System.out.println(java.util.Arrays.toString(generateRandom(size)));
    }//from   www  .  jav a2s.c  o  m

    public static byte[] generateRandom(int size) {
        byte[] iv = new byte[size];
        SecureRandom ivRandom = new SecureRandom();
        ivRandom.nextBytes(iv);
        return iv;
    }
}

Related Tutorials