Note that there are some explanatory texts on larger screens.

plurals
  1. PO3 random numbers without repetition
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/10872132/random-permutation-of-integers-using-a-random-number-generator">Random permutation of integers using a random number generator</a><br> <a href="https://stackoverflow.com/questions/14174296/how-to-make-a-random-number-but-it-doesnt-produce-the-same-number">How to make a random number but it doesn’t produce the same number</a> </p> </blockquote> <p>i have create 3 random numbers i want those 3 numbers not repetition </p> <p>for example if the first random number is = to 3 i dont want the second number or the third number = to 3<br> and get the min number and random it on 3 buttons ten set those numbers in the buttons</p> <pre><code>package com.math4kids; import java.util.Random; import android.app.Activity; import android.os.Bundle; import android.widget.Button; public class MinNumber extends Activity { public Button result1, result2, result3; public Random random = new Random(); int[] array1 = new int[3] ; int minimum = array1[0]; //sets the first to be the smallest int num1,num2; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.minnumber); result1 = (Button)findViewById(R.id.result1); result2= (Button)findViewById(R.id.result2); result3= (Button)findViewById(R.id.result3); array1[0] = random.nextInt(10) + 1; array1[1] = random.nextInt(10) + 1;; array1[2] = random.nextInt(10) + 1;; for (int i = 0; i &lt; array1.length; i++) //goes through your array { if (array1[i] &lt; array1[0]) //checks and replaces if necessary { minimum = array1[i]; } if(array1[0]==minimum){ num1=array1[1]; num2=array1[2]; } if(array1[1]==minimum){ num1=array1[0]; num2=array1[2]; } if(array1[2]==minimum){ num1=array1[1]; num2=array1[0]; } switch (random.nextInt(3)) { case 0: result1.setText(String.valueOf(minimum)); result2.setText(String.valueOf(num1 )); result3.setText(String.valueOf(num2 )); break; case 1: result2.setText(String.valueOf(minimum)); result1.setText(String.valueOf(num1)); result3.setText(String.valueOf(num2)); break; case 2: result3.setText(String.valueOf(minimum)); result2.setText(String.valueOf(num1)); result1.setText(String.valueOf(num2)); break; } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload