jeudi 25 mai 2017

Why are my generated randomly values are the same when I am put them in array?

I am sorry for this question, but I am confused. Why are randomly generated values the same in the array ?

When I am looking in the debag mode, I see that the values are the same in ArrayList<String>.

Can please anybody explain this ?

public class CreateRandomSet {
    public static void main(String[] args) throws IOException {
        Map<String, ArrayList<String>> randomSet = new HashMap<String, ArrayList<String>>();
        ArrayList<String> storeData = new ArrayList<String>();
        String fileName = "file.txt";
        FileReader fileReader = new FileReader(fileName);
        BufferedReader bf = new BufferedReader(fileReader);
        String line = bf.readLine();
        String storeId;
        String storeName;
        String customer;
        String value;
        Random random = new Random();
        double randomValue;
        double start = 100;
        double end = 10000;
        while(line != null){
            storeData.clear();
            line = line.trim();
            CsvTokenizer csvTokenizer = new CsvTokenizer(line, ",");
            storeId = csvTokenizer.nextToken();
            if(csvTokenizer.hasMoreTokens()){
                storeName = csvTokenizer.nextToken();
                storeData.add(storeName);
            }
            if(csvTokenizer.hasMoreTokens()){
                value= csvTokenizer.nextToken();
                randomValue = end + (start * random.nextDouble()) ;
                storeData.add(String.valueOf(randomValue));
            }

            randomSet.put(storeId, storeData);
            line = bf.readLine();
        }
    }
}




Aucun commentaire:

Enregistrer un commentaire