i'm new in android & java.
i used random class and setSeed for get different integer. but it's result same everything. why, and how i can solve it.
private void show_fortune(){
int love = getRandompercent(); //same
((TextView)findViewById(R.id.loveper)).setText(love+"%");
int money = getRandompercent(); //same
((TextView)findViewById(R.id.moneyper)).setText(money + "%");
int job = getRandompercent(); //same
((TextView)findViewById(R.id.jobper)).setText(job + "%");
int school = getRandompercent(); //same
((TextView)findViewById(R.id.schoolper)).setText(school+"%");
TextView result = (TextView)findViewById(R.id.fortune_result);
result.setText(fortune_result[fortune_arrayindex(love, money, job, school)]);
}
private int getRandompercent(){
Random random = new Random();
random.setSeed(System.currentTimeMillis());
return Math.abs(random.nextInt()%100+1); //it's value is same everything.
}
private int fortune_arrayindex(int love, int money, int job, int school){
int sum = (love+money+job+school)/4;
if (sum>=70)
return 0;
else if (sum>=50)
return 1;
else if (sum>=30)
return 2;
else
return 3;
}
Aucun commentaire:
Enregistrer un commentaire