Hi gyus,
I need to write a function that fill an array (list[])of distinct integers following this algorithm:
1- get a random integer with a function myrandom.
2- See if the integer already appears in list[]; if not, put it in the next position available in perm.
then repeat 1 and 2 until the end of the array.
Please , can I have some suggestions especially on how to check if the earlier element of list are ALL DIFFERENT of the integer I want to add in list[].
Thank you
I need to write a function that fill an array (list[])of distinct integers following this algorithm:
1- get a random integer with a function myrandom.
2- See if the integer already appears in list[]; if not, put it in the next position available in perm.
then repeat 1 and 2 until the end of the array.
Rich (BB code):
random=myrandom(n);
list[0]=random; /* initialized list[]*/
for(i=1;i<=n;i++)
{random=myrandom(n);
for(j=0;j<=i,j++) /* checking earlier elements*/
.......
.......(/* all I tried below to see if all elements ar different that what I need to add
does not work*/)
........
........
if(list[j]!=random)
random=myrandom(n);
}
Thank you