Java Random Byte Array randomBytes(int minimumCharacters, int maximumCharacters)

Here you can find the source of randomBytes(int minimumCharacters, int maximumCharacters)

Description

random Bytes

License

Open Source License

Declaration

public static byte[] randomBytes(int minimumCharacters, int maximumCharacters) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Random;

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

    public static byte[] randomBytes(int minimumCharacters, int maximumCharacters) {
        int n = rand(minimumCharacters, maximumCharacters);
        byte b[] = new byte[n];
        for (int i = 0; i < n; i++)
            b[i] = (byte) rand('a', 'z');
        return b;
    }//from   w  ww .j  av a2  s  . c om

    public static int rand(int lo, int hi) {
        int n = hi - lo + 1;
        int i = rn.nextInt() % n;
        if (i < 0)
            i = -i;
        return lo + i;
    }
}

Related

  1. randomBytes()
  2. randomBytes(byte[] bytes)
  3. randomBytes(final int numBytes)
  4. randomBytes(int length)
  5. randomBytes(int length)
  6. randomBytes(int size)
  7. randomBytes(long seed, int blockCount, int blockSize)
  8. randomBytes(Random r, int length)
  9. randomBytes(Random rand, int size)