I need to generate random numbers within a range ... so long, however, I need to do this for each position of the array, for example, in position 1 of my array, random numbers should be inserted in a range of 10 to 20 , at position 2, random numbers in a range 30 to 40 and so on. The starting position and the final position will already be filled.
- Code snippet -
Random r = new Random();
int v[] = new int[capacity];
v[0] = 0;
v[capacity - 1] = 15;
for (int i = 1; i < v.length - 1; i++) {
switch (i) {
case 1:
v[i] = 1 + r.nextInt(2);
break;
case 2:
v[i] = 4 + r.nextInt(3);
break;
case 3:
v[i] = 8 + r.nextInt(3);
break;
case 4:
v[i] = 12 + r.nextInt(2);
break;
}