So, if you want 0-40, you can multiple it by 40, the highest the result can ever be is what you're multiplying by. Once we figured out the minimum and maximum value, then generated a random integer value between the minimum and maximum values. Hello!Nice to meet you all! October 14, 2014, 9:02am #1. To get the Random int values we utilise the java.util.Math provided under java library. Assigning values whilst creating a 2D array. * If minVal is not given, the default value is 0. So randomFoodIndex will create a random number from 0 to 3. In programing we occasionally find the need to fill an array with random numbers. Another approach, just for the records, could be using generators. Arrays use numbers to access its "elements". We have used nextInt here for random numbers − for (int i = 0; i < val.length; i++) { val[i] = new Random().nextInt(100); System.out.println(val[i]); } Now, get the min and max values. let n=100; I have this homework I don't want it to be solved .. just some guidance. Why does my halogen T-4 desk lamp not light up the bulb completely? Both the above code create new array of six elements, each element having value as undefined. something like this will work, depending on if you want to double or ints, etc Random random = new Random (); int [] array = random. site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. What are the objective issues with dice sharing? Well, mathematically speaking it's random, all right. ints(100000, 10,100000). Of course, we can use this function to pick any random value from an array, not only colors. gambler's fallacy might believe that this next flip was less likely to start_index. Parameters. I am trying to do point 3 which is to choose the random position K of the array. The fill() method changes all elements in an array to a static value, from a start index (default 0) to an end index (default array.length). whisher. It's a random value. (I'm not critizing the answer, just raising a flag for future readers.