Reputation: 1811
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.
Upvotes: 0
Views: 284
Reputation: 947
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;
Upvotes: 1