Generate a uniform distribution of 100 random integers between 1 and 10 inclusive.
The class Random returns pseudo-random values. According to the documentation, the default no arg constructor seed is "unlikely to be duplicated by a subsequent instantiation".
public class MainActivity extends Activity {
Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Random r = new Random();
for (int i = 0; i < 100; i++) {
int N = r.nextInt(10) + 1;
Log.d("Random Integers", " N = " + N);
}
}
});
}
}
See:
http://developer.android.com/reference/java/util/Random.html