I am writing a word-learning application for android.
To get random word I use:
Random rnd = new Random();
final int rnd.nextInt(WordsNumber);
To get random direction (show word or show translation) I use:
Random rnd = new Random();
final boolean dir.nextBoolean();
But I see, that a words are not uniformly distributed. I'm testing the application with 17 words. Some words are shown 10 times, some are shown only once. The same problem is with direction. It often happens, for the fifth consecutive time direction is the same.
Maybe someone know, how to make distribution of words more equal?
UPD: I've written a test application. It generates new number on button click:
public class About extends Activity
{
final int N = 10;
int[] results;
Random rnd;
int total;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
results = new int[N];
for (int i = 0; i < N; i++)
{
results[i] = 0;
}
rnd = new Random();
total = 0;
}
public void GenerateNumber(View view)
{
int number = rnd.nextInt(N);
results[number]++;
total++;
String output = new String();
TextView txt = (TextView)findViewById(R.id.text1);
output += "Total numbers: " + String.valueOf(total) + "\n";
for (int i = 0; i < N; i++)
{
output += String.valueOf(i) + ": " + String.valueOf(results[i]) + "\n";
}
txt.setText(output);
}
}
Here are the test results:
Maybe, with N=10000 it will be equal... But for my application it's a poor consolation.
final int rnd.nextInt(WordsNumber);
is called on button click. ok, I'll write a test, but a little bit later (on Monday).