/*----------------------------------------------------------------------*/
/* Begin of Sample Loop */
/*----------------------------------------------------------------------*/
while ( sample < sample_size ) {
/* ==== Reset the walker to the origin ==== */
w[0][0] = xc;
w[0][1] = yc;
x = xc;
y = yc;
l = 0;
occupancy = 0;
walk++;
return_code = r250( N,ran,mf);
while ( (l < N) && (occupancy == 0) ) {
d = ran[l] * 4;
switch (d) {
case 0: x++;
break;
case 1: y++;
break;
case 2: x--;
break;
case 3: y--;
break;
}
if ( ( x < 0 ) || ( x == L ) || ( y < 0 ) || (
y == L ) ) {
/* Random walker not on the
lattice */
exit(-1);
}
if ( g[x][y] < walk ) {
g[x][y] = walk;
l++;
w[l][0] = x;
w[l][1] = y;
occupancy = 0;
} else {
occupancy = 1;
}
}
/* ==== Now check if a SAW was generated. If yes, then ==== */
/* ==== we do the analysis, else we must try again ==== */
if ( l == N ) {
/* ---- we can compute the end-to-end distance etc. ---- */
x = xc - w[N-1][0];
y = yc - w[N-1][1];
end_to_end += x*x + y*y;
cmx = 0;
cmy = 0;
for (i=0; i < N; i++) {
cmx += w[i][0];
cmy += w[i][1];
}
cmx /= N;
cmy /= N;
rad = 0;
for (i=0; i < N; i++) {
x = cmx - w[i][0];
y = cmy - w[i][1];
rad += x*x + y*y;
}
radius_of_gyration += rad;
sample++;
}
}