Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4050080
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:01:32+00:00 2026-05-20T14:01:32+00:00

I am looking to initialise a multidimensional array with random numbers between 0 and

  • 0

I am looking to initialise a multidimensional array with random numbers between 0 and 100 (inclusive). I am able to create the multidimensional array with empty values at each field and am then able to add 100 random numbers into the available positions.

However, I would like to know if there is a way of initialising the multidimensional array with random natural integers. For example, I am looking to do it a little something like this:

double[][] array = new double[][] {{0, 1, 2} , {1, 0, 3} , {2, 3, 0}};

Is this possible? I’m thinking something along the lines of:

double[][] array = new double[][] {{random values go here},{random values go here}};

Any suggestions?

Thank you all for taking the time to read.

Mick

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T14:01:33+00:00Added an answer on May 20, 2026 at 2:01 pm

    Create the array and then initialize it in a for loop.
    Random.nextInt(n) gives you what you need.

    Here’s a sample code with three different runs.

    import java.util.*;
    class Init { 
        public static void main( String ... args ) { 
    
            Random random = new Random();
    
            double[][] array = new double[10][10];
    
            for( int i = 0 ; i < array.length ; i++ ) { 
               for ( int j = 0 ; j < array[i].length ; j++ ) { 
                  array[i][j] = random.nextInt(101);
               }
            }
    
            for( double[] a : array ) { 
                System.out.println( Arrays.toString( a ));
            }
        }
    }
    

    Output:

    C:\Users\oreyes\langs\java>java Init
    [2.0, 92.0, 31.0, 98.0, 3.0, 5.0, 57.0, 41.0, 29.0, 89.0]
    [54.0, 57.0, 68.0, 92.0, 11.0, 20.0, 14.0, 58.0, 84.0, 23.0]
    [48.0, 14.0, 9.0, 33.0, 9.0, 27.0, 74.0, 34.0, 85.0, 91.0]
    [51.0, 87.0, 2.0, 96.0, 52.0, 81.0, 91.0, 95.0, 19.0, 56.0]
    [15.0, 90.0, 9.0, 85.0, 51.0, 23.0, 35.0, 21.0, 78.0, 14.0]
    [23.0, 20.0, 57.0, 94.0, 69.0, 99.0, 90.0, 78.0, 61.0, 38.0]
    [35.0, 61.0, 81.0, 72.0, 3.0, 93.0, 20.0, 96.0, 9.0, 35.0]
    [90.0, 100.0, 98.0, 14.0, 95.0, 75.0, 96.0, 8.0, 87.0, 25.0]
    [14.0, 41.0, 27.0, 57.0, 32.0, 37.0, 69.0, 61.0, 5.0, 42.0]
    [57.0, 0.0, 85.0, 28.0, 78.0, 47.0, 89.0, 54.0, 50.0, 59.0]
    
    C:\Users\oreyes\langs\java>java Init
    [3.0, 27.0, 37.0, 31.0, 52.0, 19.0, 63.0, 81.0, 88.0, 12.0]
    [80.0, 27.0, 7.0, 55.0, 21.0, 100.0, 73.0, 62.0, 9.0, 91.0]
    [85.0, 50.0, 66.0, 27.0, 63.0, 44.0, 0.0, 37.0, 93.0, 82.0]
    [73.0, 57.0, 4.0, 80.0, 5.0, 51.0, 63.0, 13.0, 97.0, 11.0]
    [87.0, 62.0, 20.0, 14.0, 44.0, 77.0, 71.0, 42.0, 27.0, 82.0]
    [37.0, 32.0, 96.0, 95.0, 45.0, 8.0, 11.0, 38.0, 61.0, 6.0]
    [34.0, 67.0, 84.0, 50.0, 38.0, 64.0, 50.0, 51.0, 50.0, 47.0]
    [79.0, 31.0, 54.0, 37.0, 27.0, 54.0, 57.0, 30.0, 77.0, 36.0]
    [74.0, 20.0, 98.0, 37.0, 8.0, 17.0, 18.0, 1.0, 29.0, 56.0]
    [21.0, 4.0, 33.0, 87.0, 4.0, 76.0, 65.0, 62.0, 76.0, 96.0]
    
    C:\Users\oreyes\langs\java>java Init
    [17.0, 3.0, 78.0, 32.0, 99.0, 76.0, 94.0, 93.0, 31.0, 55.0]
    [4.0, 25.0, 63.0, 68.0, 58.0, 39.0, 7.0, 55.0, 73.0, 86.0]
    [96.0, 89.0, 6.0, 100.0, 20.0, 58.0, 100.0, 91.0, 35.0, 46.0]
    [3.0, 16.0, 88.0, 82.0, 85.0, 35.0, 0.0, 1.0, 91.0, 78.0]
    [3.0, 33.0, 77.0, 10.0, 69.0, 60.0, 75.0, 58.0, 8.0, 31.0]
    [72.0, 36.0, 2.0, 19.0, 39.0, 15.0, 5.0, 74.0, 16.0, 28.0]
    [48.0, 71.0, 38.0, 17.0, 37.0, 34.0, 80.0, 98.0, 16.0, 42.0]
    [66.0, 74.0, 96.0, 80.0, 75.0, 7.0, 14.0, 46.0, 63.0, 56.0]
    [4.0, 15.0, 8.0, 93.0, 58.0, 21.0, 81.0, 100.0, 2.0, 44.0]
    [20.0, 71.0, 41.0, 43.0, 83.0, 7.0, 60.0, 28.0, 99.0, 42.0]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a looking to initialize an array/list of objects that are not empty --
I am looking for an method to create and mulidimensional array in objective C.
Is there a way to initialise an array of integers (or possibly any array)
I am looking to create a custom button on the TinyMCE toolbar that wraps
I'm looking to create an Outlook style UI in a Java desktop app, with
I just learned about this fine looking syntax Collections.<String>emptyList() to get an empty List
I'm looking for a random number generator in JavaScript which I can initialize with
I'm looking for the best way to initialize a knockout observable array from some
How could one initialize and set an array at the same time? I'm looking
I'm looking for a way to define a base constructor, that will initialize values

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.