Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ❤ 💻
We are community that shares solutions with each other.

If you think you have something to add here.

you are welcome with your fresh ideas - List Articles

Java - generate array with 10 random numbers

0 contributions
9 points

Generate array with 10 random numbers in range 60 and 100.

We can change min and max value to any Integer value, also negative.

// 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));


We can adjust the above code to generate array with 10 random longs, floats or doubles.
To get the code for random min max long, float, double check post:
https://dirask.com/q/zjM2x1

and hashtag #random-min-max with methods for int, long, float, double to generate numbers in range min and max
https://dirask.com/hashtags/random-min-max

There are other ways to generate random integer in range min-max, look at this post:
https://dirask.com/q/VjoP81

References

ThreadLocalRandom - Java docs
Random - Java docs

0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more