New seed in every iteration of for()?

I have a small problem with rand(). It seems that in every iteration it outputs the same exact numbers... So, what function should i use, so that in every iteration i get new pseudorandom numbers?

Here's the code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

void main(){
int d=2,i,N=10;
float x[2000],y[2000],distmin[2000],amax,bmax;

float distminmax=0;

srand(clock());

for(int k=1;k<=d+1;k++){
x[k]=(rand()%10000)/10000.0;
y[k]=(rand()%10000)/10000.0;
printf("%f\n%f\n\n",x[k],y[k]);
};

for (int l=d+2;l<=N;l++){
//srand(l);


for (i=1;i<=1000;i++){
//srand(i);
time(&seconds);
srand((unsigned int) seconds);

float a=(rand()%10000)/10000.0;
float b=(rand()%10000)/10000.0;

distmin[i]=1;

for(int j=1;j<=l-1;j++){
float dist=sqrt((a-x[j])*(a-x[j])+(b-y[j])*(b-y[j]));
if(dist<distmin[i]){
distmin[i]=dist;
};
};

if(distmin[i]>distminmax){
distminmax=distmin[i];
amax=a;
bmax=b;
};


};
x[l]=amax;
y[l]=bmax;
printf("%f\t%f\t%f\n",distminmax,x[l],y[l]);
};
}


Thx in advance.
[code]Your code goes here[/code]
You need to call to srand only one time in your entire program. Every time you call it the seed is generated, so if you use the same seed the pseudo random numbers will be the same.
Thx!
Topic archived. No new replies allowed.