0

i'm trying to make a method which can generate 100 random numbers between 14-24, and place it in my byte array before i'm going to send it to a server.

My code so far looks like this:

private byte data[] = new byte[100];

public void generateData() {
    int min = 14;
    int max = 24;

    for (int i = 0; i < 100; i++) {

        data[i] 

    }

}

So for every step in the array, it should put in a byte number between 14-24.. but when i'm trying to use the Math.random, it only works with double.

Mikkel
  • 1,771
  • 11
  • 35
  • 59
  • Check this SO link http://stackoverflow.com/questions/6029495/how-can-i-generate-random-number-in-specific-range-in-android – HJK Feb 13 '15 at 12:00

2 Answers2

1

You can use the Random class. Generate a random number between 0 and 10 and add 14 to it.

Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(11) + 14;
DeiAndrei
  • 947
  • 6
  • 16
0
int x = (int)(Math.random()*100000000l); 
int randomNo = x%14+14;
Arvind
  • 1,207
  • 6
  • 27
  • 55