public class RandomBlockGenerator {
List<String> bin;
public RandomBlockGenerator (List<String> blockList, List<String> weightList)
{
bin = new ArrayList<String>(100000);
int counter = 0;
for(int i = 0; i < blockList.size(); i++)
{
for(int j = 0; j < (Double.parseDouble(weightList.get(i)) * 1000); j++)
{
bin.add(blockList.get(i));
counter++;
}
counter = 0;
}
}
public int next()
{
Random seed = new Random();
int rand = Integer.parseInt(bin.get(seed.nextInt(bin.size())));
return rand;
}
}
Numbers stored as strings, repeatedly parsed to their numeric types, a 100,000 element string array... It's not good.

New Topic/Question
Reply



MultiQuote


|