You can use IntStream ints() or DoubleStream doubles() available as of java 8 in Random class. something like this will work, depends if you want double or ints etc.

Random random = new Random();

int[] array = random.ints(100000, 10,100000).toArray();

you can print the array and you'll get 100000 random integers.

Answer from Samir Ouldsaadi on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java array › how to fill an array with random numbers
How to Fill an Array With Random Numbers - Java
August 13, 2024 - Among the various available approaches, we can iteratively fill the content of an array with random numbers using the methods provided by the Random, SecureRandom, and ThreadLocalRandom classes, which are suitable for different scenarios.
Discussions

[Java] Trying to fill an array with unique random numbers.
So you need to fill an array with unique random numbers. You need an array. You need to loop through each position of the array. At each position, generate a random number Try it with only One loop. If you get stuck, feel free to let me know. More on reddit.com
🌐 r/learnprogramming
7
1
November 15, 2014
java - How to fill an array with random numbers from 0 to 99 using the class Math? - Stack Overflow
4 Java - how to create a random number from an array of values More on stackoverflow.com
🌐 stackoverflow.com
September 10, 2014
2d array filled with random numbers
Your print statement is inside the inner loop (the column loop). That will make it print the array everytime you just want to allocate a random int to the next cell. You should have the print statement outside the outer loop ( the row loop), so that it only prints the whole array once after you have assigned all random variables. Similarly you also do not need the println statement within each row loop. As it will just end up printing a new line the number of times the array has rows. Finally check your terminating condition for both the outer and inner loops. With the current conditions you will get one less row and one less column than what you expected. More on reddit.com
🌐 r/learnjava
5
1
March 10, 2024
Java fill an array with random with random numbers - Stack Overflow
I have a homework assignment where a user must input the size of an array and then the array must be filled with random values. I am having issues filling the array with something that isn't garbage More on stackoverflow.com
🌐 stackoverflow.com
🌐
TutorialsPoint
tutorialspoint.com › java-program-to-fill-an-array-with-random-numbers
Java Program to fill an array with random numbers
import java.util.Arrays; import java.util.Random; public class Demo { public static void main(String args[]) { double[] arr = new double[5]; Random randNum = new Random(); for (int i = 0; i < 5; i++) { arr[i] = randNum.nextInt(); } System.out.println("Random numbers = "+Arrays.toString(arr)); } }
🌐
Coderanch
coderanch.com › t › 688929 › java › Fill-array-random-numbers
Fill an array with random numbers (Beginning Java forum at Coderanch)
December 31, 2017 - To part which is difficult to me is the one were i must create a method which must choose a random Position of the array everytime and based on that position --lets say k--to sort the number in the array with ascending order until k and from position (k +1) to sort with descending order the rest numbers. Well,i am confused on how to find this random Position.. Any Ideas,please? ****Sorry,if my english isnt the best****** ... John, Welcome to CodeRanch! Java comes with a random number generator.
🌐
Reddit
reddit.com › r/learnprogramming › [java] trying to fill an array with unique random numbers.
r/learnprogramming on Reddit: [Java] Trying to fill an array with unique random numbers.
November 15, 2014 -

Hello!

I'm learning to program at school now, and i have a problem i can't figure out. I'm trying to create an array and fill it with random numbers. But i want the numbers to be unique.

int[] list = new int[10];

list[0] = r.nextInt(20);

for(int i = 1; i < list.length; i++) {

 list[i] = r.nextInt(20);
 for(int j = 0; j < i; j++) {
      while(list[i] == list[j]) {
             list[i] = r.nextInt(10);
      }
 }

}

I can not figure out how to make this work and it is really bugging my mind. Does anybody have any tips?

Edit* Sorry for the messed up edit. first time posting code, so i don't know how to make it appear as code yet :)

🌐
Java2Blog
java2blog.com › home › core java › random › fill array with random numbers in java
Fill Array With Random Numbers in Java - Java2Blog
May 18, 2022 - You can fill the integer array with random numbers using the Math class by following the given steps. Declare and instantiate an integer array. ... Generate a double number by invoking the Math.random() method. Multiply the result with a large integer. The code given here multiplies the number ...
🌐
Java2s
java2s.com › Tutorials › Java › Collection_How_to › Array › Fill_an_array_with_random_numbers.htm
Java Collection How to - Fill an array with random numbers
We would like to know how to fill an array with random numbers. import java.util.Arrays; import java.util.Random; // ww w.j a v a2s .
Find elsewhere
🌐
YouTube
youtube.com › watch
[Java Basics] Filling an int Array with Random Numbers in Java - YouTube
AboutPressCopyrightContact usCreatorsAdvertiseDevelopersTermsPrivacyPolicy & SafetyHow YouTube worksTest new featuresNFL Sunday Ticket · © 2026 Google LLC
Published   December 4, 2017
🌐
Coderanch
coderanch.com › t › 656330 › java › Populating-array-random-numbers
Populating an array with random numbers (Beginning Java forum at Coderanch)
Try int[] randomNumbers = new Random().ints(10L, 100, 200).toArray(); That will give you a ten‑element array containing numbers “randomly” chosen between 100 and · 199. Obviously you can put different numbers in there. If you click on the ints link you find it creates an IntStream which ...
🌐
YouTube
youtube.com › simplecode
JAVA Simple Array with random numbers - YouTube
simple how-to fill an array with random integers using Math.random() function. Music : Podington Bear "Arboles"
Published   June 21, 2015
Views   11K
🌐
Reddit
reddit.com › r/learnjava › 2d array filled with random numbers
r/learnjava on Reddit: 2d array filled with random numbers
March 10, 2024 -

Hi I need some desperate help, in my hw im supposed to do a 2d array and fill it with random number to add them later but my issue is the array in itself because for the love of everything this is not working. I also tried the math.random but still get the same problem

The first time I got this when running the program [I@28a418fc[[I@28a418fc and i looked up how to solve it, it said to use arrays.deeptostring to change the hash codes into actual numbers and to not use println but now I get this [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]][[84, 121, 30, 67, 138], [102, 87, 58, 95, 140], [113, 64, 80, 109, 104], [39, 122, 100, 85, 40], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] an i havent found what exactly this is either.

This is what I have so far

import java.util.Arrays;
import java.util.Random;

public class ejercicio6 {

    public static void main(String args[]) {


        int matriz [][] = new int [6][5];

        Random rand = new Random();

        for (int i = 0; i < matriz.length - 1; i++){ //filas

            for(int j = 0; j < matriz.length - 1; j++){ //columnas

                matriz[i][j] = rand.nextInt(150 -10 + 1) + 10;
                System.out.print(Arrays.deepToString(matriz)); //deepToString porque me salen los hashcodes [I@5305068a

            }
            System.out.println("");
        }
🌐
Stack Overflow
stackoverflow.com › questions › 42868351 › java-fill-an-array-with-random-with-random-numbers
Java fill an array with random with random numbers - Stack Overflow
args) { int[] array = new int[10]; ... = "+array[i]); } } static void randomFill(int[] array) { Random rand = new Random(); for(int i = 0; i < array.length ; i++){ array[i] = rand.nextInt(); } } } ... array[0] = 431970257 array[1] ...
🌐
Reddit
reddit.com › r/javahelp › how to populate an entire array with random numbers from low to high (low and high are both variables)
r/javahelp on Reddit: How to populate an entire array with random numbers from low to high (low and high are both variables)
September 26, 2022 -

Hey! First time posting, I just need some guidance on how to complete this question (I'm just now getting into Java). Alright so this is what I have so far.

public int makeIntArray(int size, int low, int high)
{
    int [] array1 = new int [size];
    for(int i = 0; ???)

}

Alright, where the "???" is, is where I'm stuck. I'm not sure if I'm even supposed to use a for loop to tackle this question. All the information for this question, the method is called makeIntArray and it has three int parameters, size, low, and high, I needed to create an array based on the size parameter (I did that), and now I have to populate the array with random numbers from low to high. I just want someone to help me tackle this question so in the future, I can handle this question with no help. Thanks!

🌐
GeeksforGeeks
geeksforgeeks.org › java › add-random-number-to-an-array-in-java
How to Add Random Number to an Array in Java? - GeeksforGeeks
July 23, 2025 - // Java Program to Add Random Number to an Array import java.util.Random; import java.util.*; public class Main { public static void main(String[] args) { int n = 5; int[] arr = new int[n]; // Create a Random object Random random = new Random(); // ...
🌐
5balloons
5balloons.info › java-code-to-fill-int-double-array-with-random-values
Java Code to fill int / double Array with random values. - 5Balloons Tech
June 1, 2017 - import java.util.Arrays; public class ArrayRandomValues { public static void main(String args[]) { int[] myIntArray = new int[100]; for (int i = 0; i < myIntArray.length; i++) { myIntArray[i] = (int) (Math.random() * 100); } System.out.println(Arrays.toString(myIntArray)); double[] myDoubleArray = new double[100]; for (int i = 0; i < myDoubleArray.length; i++) { myDoubleArray[i] = Math.random() * 100; } System.out.println(Arrays.toString(myDoubleArray)); } }
🌐
Java Mex
javamex.com › tutorials › java › arrays_2.shtml
Java programming tutorial: arrays (2)
Now that we've filled our array with random numbers, we can print out those random numbers as follows: for (int i = 0; i < randomNumbers.length; i++) { System.out.println("Position " + i + " : " + randomNumbers[i]); } If you put the above fragments together, and run the program, you should find it outputs a list of 20 random numbers. On the next page, we look at sorting the array. If you enjoy this Java programming article, please share with friends and colleagues.
🌐
Know Program
knowprogram.com › home › java fill 2d array with random numbers
Java Fill 2d Array With Random Numbers - Know Program
April 25, 2022 - For example:- array[ ][ ] = new int[2][2] Generate random number and insert into the array. Result:- 1 2 3 4 · The random module has generated some random integers, in the program we just need to give the number of rows and columns. Observe the below code. Now let us see a Java program to fill a 2d array with random numbers.
🌐
TutorialsPoint
tutorialspoint.com › generate-a-random-array-of-integers-in-java
Generate a random array of integers in Java
September 12, 2023 - import java.util.Random; public ... ? The output might vary on Online Compilers. Here we use the nextInt() method in a loop to get a random integer for each element....
🌐
Stack Overflow
stackoverflow.com › questions › 20337253 › how-to-fill-an-array-with-random-integers-and-create-a-button-to-activate-it
java - How to fill an array with random integers and create a button to activate it - Stack Overflow
Purpose is to create an array which will start with a button click and fill the array with random int ranging from 0 to 100 · import java.awt.*; //imports data from library import java.awt.event.*; import javax.swing.*; public class FinalArray extends JFrame implements ActionListener { private JButton fill, private JTextArea output; public static void main(String[] args) { //creates window FinalArray demo = new FinalArray(); demo.setSize(400,450); demo.createGUI(); demo.setVisible(true); } private void createGUI() { setDefaultCloseOperation(EXIT_ON_CLOSE); Container window = getContentPane();