Assign unique random integers in an array (C) -


im struggling long, can fill array random numbers not unique. can't spot problem in code :( can me? thanks

int getuniquenumber(int *p, int i) {     int x,j,found;         {         x=rand()%100000 + 1;         found=0;         j=0;         while(j<=i && found==0)         {             if(p[i]==x)                 found=1;             else                 j++;         }     } while(found==1);     return x; } 

p[i] == x should p[j] == x.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -