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.
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;
int x = (int)(Math.random()*100000000l);
int randomNo = x%14+14;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.