Search:

Type: Posts; User: Blackrabbitjack

Search: Search took 0.11 seconds.

  1. Replies
    4
    Views
    1,815

    Re: Picking Random Element from Array

    public void randomGen(String[] x) {
    int rand = rangen.nextInt(x.length-2);
    JOptionPane.showMessageDialog(null, "Randomly chosen word is: " + x[rand]);
    }

    For anyone...
  2. Replies
    4
    Views
    1,815

    Re: Picking Random Element from Array

    Would this be the proper way to use this utility?


    public void randomGen(String[] x) {
    Random rangen = new Random();
    int rand = rangen.nextInt(x.length-1);

    }
  3. Replies
    4
    Views
    1,815

    Picking Random Element from Array

    Not too sure if this is the right place to post this, so if it isn't, I apologize. Still figuring out my way around here.

    Anyways, what is the best way to grab a random element from an array?...
Results 1 to 3 of 3