Advertisement
jbjares

randomLoc

May 10th, 2015
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. import java.io.File;
  2. import java.util.Random;
  3. import java.util.Scanner;
  4.  
  5. public class RandomCountryLatLngDataUtil {
  6.  
  7.     public static String[] choose() {
  8.         String result = null;
  9.         try{
  10.             File f = new File("src/main/resources/countriesLatLng.csv");
  11.             Random rand = new Random();
  12.             int n = 0;
  13.             for (Scanner sc = new Scanner(f); sc.hasNext();) {
  14.                 ++n;
  15.                 String line = sc.nextLine();
  16.                 if (rand.nextInt(n) == 0)
  17.                     result = line;
  18.             }
  19.            
  20.         }catch(Exception e){
  21.             throw new RuntimeException(e.getMessage(),e);
  22.         }
  23.  
  24.         return result.split(";");
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement