Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Random;

public class Main {
    private static final Random random = new Random();

    public static byte[] appendRandomBytes(int len, byte... b) {
        byte[] ret = new byte[len + b.length];
        System.arraycopy(b, 0, ret, 0, b.length);
        System.arraycopy(genRandomBytes(len), 0, ret, b.length, len);
        return ret;
    }

    public static byte[] genRandomBytes(int len) {
        if (len <= 0) {
            throw new IllegalArgumentException("Length must > 0: " + len);
        }
        byte[] ret = new byte[len];
        for (int i = 0; i < ret.length; i++) {
            ret[i] = (byte) random.nextInt(256);
        }
        return ret;
    }
}