create Random Bytes - Java java.lang

Java examples for java.lang:byte Array

Description

create Random Bytes

Demo Code


//package com.java2s;
import java.util.Random;

public class Main {
    public static void main(String[] argv) throws Exception {
        byte[] bytes = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };
        System.out.println(java.util.Arrays
                .toString(createRandomBytes(bytes)));
    }// ww  w  . j  a v  a2 s  . co  m

    public static byte[] createRandomBytes(byte[] bytes) {
        if (bytes != null) {
            Random random = new Random();
            random.nextBytes(bytes);
        } else {
            throw new NullPointerException("????????");
        }
        return bytes;
    }
}

Related Tutorials