title: Randomizing text file read in Java
body: <p>I am trying to read a text file in Java, basically a set of questions. With four choices and one answer. The structure looks like this:</p>
  <blockquote>
  <p>question</p>
  <p>option a</p>
  <p>option b</p>
  <p>option c</p>
  <p>option d</p>
  <p>answer</p>
  </blockquote>
  <p>I have no trouble reading it that way:</p>
  <pre><code>public class rar{
  public static String[] q=new String[50];
  public static String[] a=new String[50];
  public static String[] b=new String[50];
  public static String[] c=new String[50];
  public static String[] d=new String[50];
  public static char[] ans=new char[50];
  public static Scanner sr= new Scanner(System.in);
  
  
  public static void main(String args[]){
  int score=0;
  try {
               FileReader fr;
        fr = new FileReader (new File(&quot;F:\\questions.txt&quot;));
        BufferedReader br = new BufferedReader (fr);
  int ar=0;
        for(ar=0;ar&lt;2;ar++){
        q[ar]=br.readLine();
        a[ar]=br.readLine();
        b[ar]=br.readLine();
        c[ar]=br.readLine();
        d[ar]=br.readLine();
      String tempo=br.readLine();
      ans[ar]=tempo.charAt(0);
      
        
        
        
      
        
          System.out.println(q[ar]);
          System.out.println(a[ar]);
          System.out.println(b[ar]);
          System.out.println(c[ar]);
          System.out.println(d[ar]);
          System.out.println(&quot;Answer: &quot;);
          String strans=sr.nextLine();
  char y=strans.charAt(0);
  if(y==ans[ar]){
      System.out.println(&quot;check!&quot;);
  score++;
  System.out.println(&quot;Score:&quot; + score);
  }else{
  System.out.println(&quot;Wrong!&quot;);
  }
          
        }
        br.close();
      } catch (Exception e) { e.printStackTrace();}
  
  
  }
  
   
  
  
  }
  </code></pre>
  <p>The code above is predictable. The for loop just increments. And it displays the questions based on order.</p>
  <p>What I want to do is to be able to randomize through the text file, but still maintaining the same structure. (q, a, b, c, d, ans).
  But when I try to do this:</p>
  <pre><code>int ran= random(1,25);
     System.out.println(q[ran]);
          System.out.println(a[ran]);
          System.out.println(b[ran]);
          System.out.println(c[ran]);
          System.out.println(d[ran]);
          System.out.println(&quot;Answer: &quot;);
          String strans=sr.nextLine();
  char y=strans.charAt(0);
  if(y==ans[ran]){
      System.out.println(&quot;check!&quot;);
  score++;
  System.out.println(&quot;Score:&quot; + score);
  }else{
  System.out.println(&quot;Wrong!&quot;);
  }
  </code></pre>
  <p>And this is the method that I use for randomizing:</p>
  <pre><code>public static int random(int min, int max){
      int xx;
      xx= (int) ( Math.random() * (max-min + 1))+ min;
      return xx;
      }
  </code></pre>
  <p>There's the possibility that I get a null. What can you recommend that I would do so that I get no null when trying to randomize the questions?</p>
  <p>Can you see anything else that is wrong with my program?</p>