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
Post a Comment