Hello everyone, I need help with my program. The program has to randomize the array indexs. I am having a huge issue with this:

import java.util.Random; //to generate random #'s

public class Array
   public static void printIntArray(int[] myParamVar)
    int LOCATION = 0;   

    while(LOCATION < myParamVar.length)
       System.out.print("In LOCATION " + LOCATION + " ");
       System.out.print("Susie has written ");

       LOCATION = LOCATION + 1; 

        public static void main (String[] args )
          int[] myParamVar = {59, 39, 16, 10, -1}; 
          int random = (int)(4.9999 * Math.random());

          for(int i =0; i < myParamVar.length; i++)


It would be nice if someone point me into the right direction !!

The program has to randomize the array indexs.

What does that sentence mean??? If your program generate a random index of an array, what's next?

Your program is importing Random class, but you instead use Math.random() method to generate a number? What you need to do is to follow the Random API doc. To generate an integer, you would do it as follows:

Random rand = new Random();  // create an instance of Random class
int randomNumber = rand.nextInt(MAXIMUM_NUMBER);

// Above, the random number is generated from 0 up to MAXIMUM_NUMBER-1.
// In mathematical range notation, it is [0, MAXIMUM_NUMBER).

Then what do you want to do next with the random number???

Edited 4 Years Ago by Taywin

It seems that nobody here understands what you mean by "randomize the array indexs".
Java array indexes go from 0 to (length-1) as a strict integer sequence. The language does not allow you to change that in any way, let alone "randomise" it.
Can you re-state your requirement in a way that makes sense?

ps Java naming conventions reserve all-upper-case names for constants. Variable names should be in camel case (eg myParamVar)

Do you mean you want to scramble the order of things in an array, like shuffling a deck of cards? In that case go through the array a couple of time, swapping each element with one that has been randomly chosen from elsewhere in the array. That ought give you a randomized order.

This question has already been answered. Start a new discussion instead.