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
Discussions

java - How to randomly pick an element from an array - Stack Overflow
I am looking for solution to pick number randomly from an integer array. For example I have an array new int[]{1,2,3}, how can I pick a number randomly? More on stackoverflow.com
🌐 stackoverflow.com
java - Generate 10 Random Integers storing them in an Array and then calling a Method to display the Array - Stack Overflow
so i need to generate 10 random integers in the range 1-20 but i have to store them in an array called numbers. Then I have to call a method called displayArray which displays the contents of the a... More on stackoverflow.com
🌐 stackoverflow.com
java - How to fill an array with random numbers from 0 to 99 using the class Math? - Stack Overflow
Conversion in Java looks like cast in C. ... Sign up to request clarification or add additional context in comments. ... And is called casting as well. 2014-09-10T14:47:36.197Z+00:00 ... You need to strictfp this. 2018-11-04T20:37:19.13Z+00:00 ... When you cast, cast type should be in brackets e.g. (cast type)value ... You need to strictfp this. 2018-11-04T20:37:09.233Z+00:00 ... package studing; public class Array ... More on stackoverflow.com
🌐 stackoverflow.com
January 20, 2026
[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
🌐
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 class Example { public static void main(String[] args) { Random rd = new Random(); // creating Random object int[] arr = new int[5]; for (int i = 0; i < arr.length; i++) { arr[i] = rd.nextInt(); // storing random integers in an array System.out.println(arr[i]); // printing each array element } } }
🌐
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.
🌐
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 ... main(String[] args) { int n = 5; int[] arr = new int[n]; // Create a Random object Random random = new Random(); // Assign random values to the array for (int i = 0; i < n; i++) { // Generate a ...
🌐
TutorialsPoint
tutorialspoint.com › article › java-program-to-generate-a-random-number-from-an-array
Java program to generate a random number from an array
November 4, 2024 - Retrieve and print the random element. ... args) { int[] arr = new int[] { 10, 30, 45, 60, 78, 99, 120, 140, 180, 200}; System.out.print("Random number from the array = "+arr[new Random().nextInt(arr.length)]); } }...
Find elsewhere
🌐
CodingNConcepts
codingnconcepts.com › java › generate-random-numbers-in-java
How to generate Random Numbers in Java - Coding N Concepts
May 21, 2023 - Let’s use the above method to generate an Array of 5 random numbers between 0 to 9 inclusive. The method will generate a random array every time you run it. System.out.println(Arrays.toString(generateRandomArray(5, 0, 9))); // Prints random array "[1, 9, 7, 0, 4]" // Prints random array "[7, 1, 2, 8, 5]" // Prints random array "[5, 7, 5, 2, 3]" Let’s create a method using Random class and Java Streams to generate a List of random numbers of a given size and all elements in that List should be in the given range of min and max values inclusive.
🌐
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 ... Any Ideas,please? ****Sorry,if my english isnt the best****** ... John, Welcome to CodeRanch! Java comes with a random number generator....
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 323367 › array-of-random-numbers
java - Array of random numbers ... [SOLVED] | DaniWeb
To give you an idea of what you ... int temp; int arr[] = new int[20]; for(int i = 0; i < 20; i++) { //random numbers from 1 to 10: temp = r.nextInt(10) + 1; // this will give you a random number between 0 to 10....
🌐
OneCompiler
onecompiler.com › questions › 3xmsr4s6w › -java-how-to-create-an-array-of-random-numbers
[Java] How to create an array of random numbers? - Questions - OneCompiler
Following code shows how to generate array of length 10 with random numbers. import java.util.Arrays; import java.util.Random; import java.util.stream.IntStream; public class JavaArrays { public static void main(String[] args) { int arrayLength = 10; int maxNumber = 1000; int[] randomIntsArray = IntStream.generate(() -> new Random().nextInt(maxNumber)).limit(arrayLength).toArray(); System.out.println(Arrays.toString(randomIntsArray)); } }
🌐
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 ...
🌐
Chron.com
smallbusiness.chron.com › assign-random-numbers-array-java-29189.html
How to Assign Random Numbers to an Array in Java
August 9, 2022 - The following code instantiates the "RandomNumber" class and uses it to create a random number between one and 100:Random gen = new Random(); int randomNum= gen.nextInt(100); Add the random number to the array.
🌐
Dirask
dirask.com › posts › Java-generate-array-with-10-random-numbers-gprZAp
Java - generate array with 10 random numbers - Dirask
June 6, 2014 - // generate random numbers between 60 and 100 int minVal = 60; int maxVal = 100; int[] arr = new int[10]; for (int i = 0; i < arr.length; i++) { arr[i] = ThreadLocalRandom.current().nextInt(minVal, maxVal); } // [98, 93, 80, 61, 64, 70, 73, 64, 71, 86] System.out.println(Arrays.toString(arr));
🌐
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 :)

🌐
Coderanch
coderanch.com › t › 673266 › java › Random-numbers-array
Random numbers in a 2d array (Beginning Java forum at Coderanch)
so i would need to assing the random to a 2d array. like this? public static int[][] newRandom(int m, int n) { int[][] size = new int[m][n]; for(int i = 0; i < m; i++){ for(int j = 0; j < n ; j++){ size[i][j] = rand.nextInt(10)*10+1; } } return size; } ... JavaRanch-FAQ HowToAskQuestionsOnJavaRanch ...