Hi everyone,

My program is doing what it suppose to do, except that it generates a loop with the answer.

...
ERROR in uniform.discrete_uniform(): a=100 b=99
ERROR in uniform.discrete_uniform(): a=100 b=99
ERROR in uniform.discrete_uniform(): a=100 b=99
ERROR in uniform.discrete_uniform(): a=100 b=99
ERROR in uniform.discrete_uniform(): a=100 b=99
ERROR in uniform.discrete_uniform(): a=100 b=99
ERROR in uniform.discrete_uniform(): a=100 b=99
ERROR in uniform.discrete_uniform(): a=100 b=99
ERROR in uniform.discrete_uniform(): a=100 b=99
ERROR in uniform.discrete_uniform(): a=100 b=99
ERROR in uniform.discrete_uniform(): a=100 b=99
ERROR in uniform.discrete_uniform(): a=100 b=99
ERROR in uniform.discrete_uniform(): a=100 b=99
ERROR in uniform.discrete_uniform(): a=100 b=99
ERROR in uniform.discrete_uniform(): a=100 b=99
ERROR in uniform.discrete_uniform(): a=100 b=99
ERROR in uniform.discrete_uniform(): a=100 b=99
ERROR in uniform.discrete_uniform(): a=100 b=99
ERROR in uniform.discrete_uniform(): a=100 b=99
ERROR in uniform.discrete_uniform(): a=100 b=99
ERROR in uniform.discrete_uniform(): a=100 b=99
...

Can anyone help me?

I have attached the files necessary to run the program.

Thanks

If your return value for the error condition is not checked, why would the loop break?

void permute (int *A, int n)
{
  int i = 0;
  for (i=0; i<n; i++) {
    /* Pick a random element to move to i-th position. */
    int k = discrete_uniform (i+1, n-1);
    int temp = A[i];
    A[i] = A[k];
    A[k] = temp;
  }
}

Thank you, problem fixed!

int k = discrete_uniform (i, n-1);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.