In: Computer Science
randomGenotype()
HERE IS THE CODE
_____________________________________________________________________________________________________________________________________________________
public static Integer [] randomGenotype() { Integer [] genotype = new Integer [boardSize]; // YOUR CODE GOES HERE // DUMMY CODE TO REMOVE: genotype = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; // END OF YOUR CODE return genotype; }
import java.util.Random;
public class RandomNum {
public static void main(String args[])
{
int[] array=randomGenotype();
for(int i=0;i<12;i++)
System.out.print(array[i]+" ");
}
public static int [] randomGenotype()
{
int [] genotype = new int [12];
Random rand = new Random();
int num ;
int i=0;
do
{
num = rand.nextInt(100);
int c=1;
for(int
j=0;j<genotype.length;j++)
{
if(genotype[j]==num)
{
c=0;
break;
}
}
if(c==1)
{
genotype[i]=num;
i++;
}
else
{
continue;
}
}while(i<12);
// YOUR CODE GOES HERE
// DUMMY CODE TO REMOVE:
//genotype = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12 };
// END OF YOUR CODE
return genotype;
}
}