title: How to get a random line from text file in Android using Android Studio 2.1.3?
body: <p>I have a text file with 500 lines. I placed this text file in app/src/main/assets folder with the name "words.txt". In this file each line is separated with line break. Now i need to get random line from this text file. I visited following questions prior to posting this.</p>
  
  <p><a href="https://stackoverflow.com/questions/18157298/how-to-load-random-line-from-text-file-in-android">How to load random line from text file in android?</a> </p>
  
  <p><a href="https://stackoverflow.com/questions/8704794/inputstreamreader-and-reading-random-lines-from-txt-file">InputStreamReader and reading random lines from .txt file</a></p>
  
  <p><a href="https://stackoverflow.com/questions/30465507/how-to-grab-a-random-line-from-a-text-file-and-print-the-line">How to grab a random line from a text file and print the line [duplicate]</a></p>
  
  <p><a href="https://stackoverflow.com/questions/2218005/how-to-get-a-random-line-of-a-text-file-in-java">How to get a random line of a text file in Java?</a></p>
  
  <p><a href="https://thenewboston.com/forum/topic.php?id=2236" rel="nofollow noreferrer">Reading a random line from text file in android</a></p>
  
  <p>I have constructed my code from above links as well as <a href="https://stackoverflow.com/questions/4785628/java-random-line-read">this</a> one. I did not know that some class called line number reader exists.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>try {
          //Initialize assetmanager class
          AssetManager am = this.getAssets();
          //open file using asset manager
          InputStream is = am.open("words.txt");
          //read buffer manager
          BufferedReader reader = new BufferedReader(new InputStreamReader(is));
          //Important: use of LineNumberReader Class
          LineNumberReader lnr = new LineNumberReader(reader);
          Random r = new Random();
          int n = r.nextInt(500)+1;
          lnr.setLineNumber(n);
          mWord = lnr.readLine();
          Log.d("MyLog","The letter is "+mWord);
      } catch (FileNotFoundException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>Now this code works but always gives the first line. The random number is generated but the lnr (LineNumberReader) reads first line always. Why?</p>
  
  <blockquote>
    <p>This is for learning purpose. For current case i know the length of file (or total no of lines) are 500. </p>
  </blockquote>