00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <stdio.h>
00018 #include <stdlib.h>
00019 #include <string.h>
00020 #include <ctype.h>
00021 #include <math.h>
00022 #include <limits.h>
00023 #include <time.h>
00024
00025 #include "user.h"
00026 #if __MWERKS__ && __POWERPC__
00027 #include <SIOUX.h>
00028 #include <Files.h>
00029 #include <console.h>
00030 #include <Desk.h>
00031 #endif
00032
00033 #ifdef USE_DMALLOC
00034 #include "dmalloc.h"
00035 #endif
00036
00037 #ifdef _MSC_VER
00038 #pragma warning( disable : 4244)
00039 #endif
00040
00041 #define MINVALUE 0.8
00042 #define MAXdim 100
00043 #define PI 3.1415926535897932384
00044 #define DEFAULTzbox 1e6
00045
00046 char prompt[]= "\n\
00047 -rbox- generate various point distributions. Default is random in cube.\n\
00048 \n\
00049 args (any order, space separated): Version: 1998/1/28\n\
00050 3000 number of random points in cube, lens, spiral, sphere or circle\n\
00051 Bn bounding box coordinates, default %2.2g\n\
00052 D3 dimension 3-d\n\
00053 Xn Pm Pm generate n random points in convex hull of Pm...\n\
00054 l generate a regular 3-d spiral\n\
00055 r generate a regular polygon, ('r s Z1 G0.1' makes a cone)\n\
00056 s generate cospherical points\n\
00057 x generate random points in simplex, may use 'r' or 'Wn'\n\
00058 y same as 'x', plus simplex\n\
00059 \n\
00060 Ln lens distribution of radius n. Also 's', 'r', 'G', 'W'.\n\
00061 On offset coordinates by n\n\
00062 Pn,m,r add point [n,m,r] first, pads with 0\n\
00063 W0.1 random distribution within 0.1 of the cube's or sphere's surface\n\
00064 Z0.5 s random points in a 0.5 disk projected to a sphere\n\
00065 Z0.5 s G0.6 same as Z0.5 within a 0.6 gap\n\
00066 \n\
00067 c add a unit cube to the output ('c G2.0' sets size)\n\
00068 d add a unit diamond to the output ('d G2.0' sets size)\n\
00069 h output as homogeneous coordinates for cdd\n\
00070 n remove command line from the first line of output\n\
00071 t use time as the random number seed (default is command line)\n\
00072 tn use n as the random number seed\n\
00073 z print integer coordinates, default 'Bn' is %2.2g\n\
00074 ";
00075
00076
00077 int roundi( double a);
00078 void out1( double a);
00079 void out2n( double a, double b);
00080 void out3n( double a, double b, double c);
00081 int qh_rand( void);
00082 void qh_srand( int seed);
00083
00084
00085
00086
00087 FILE *fp;
00088 int isinteger= 0;
00089 double out_offset= 0.0;
00090
00091
00092
00093
00094
00095 int main(int argc, char **argv) {
00096 int i,j,k;
00097 int gendim;
00098 int cubesize, diamondsize, seed=0, count, apex;
00099 int dim=3 , numpoints= 0, totpoints, addpoints=0;
00100 int issphere=0, isaxis=0, iscdd= 0, islens= 0, isregular=0, iswidth=0, addcube=0;
00101 int isgap=0, isspiral=0, NOcommand= 0, adddiamond=0, istime=0;
00102 int isbox=0, issimplex=0, issimplex2=0;
00103 double width=0.0, gap=0.0, radius= 0.0;
00104 double coord[MAXdim], offset;
00105 double *simplex, *simplexp;
00106 double norm, factor, randr, rangap, lensangle= 0, lensbase= 1;
00107 double anglediff, angle, x, y, cube= 0.0, diamond= 0.0;
00108 double box= qh_DEFAULTbox;
00109 double randmax= qh_RANDOMmax;
00110 char command[200], *s, seedbuf[200];
00111 time_t timedata;
00112
00113 #if __MWERKS__ && __POWERPC__
00114 char inBuf[BUFSIZ], outBuf[BUFSIZ], errBuf[BUFSIZ];
00115 SIOUXSettings.showstatusline= False;
00116 SIOUXSettings.tabspaces= 1;
00117 SIOUXSettings.rows= 40;
00118 if (setvbuf (stdin, inBuf, _IOFBF, sizeof(inBuf)) < 0
00119 || setvbuf (stdout, outBuf, _IOFBF, sizeof(outBuf)) < 0
00120 || (stdout != stderr && setvbuf (stderr, errBuf, _IOFBF, sizeof(errBuf)) < 0))
00121 fprintf ( stderr, "qhull internal warning (main): could not change stdio to fully buffered.\n");
00122 argc= ccommand(&argv);
00123 #endif
00124 if (argc == 1) {
00125 printf (prompt, box, DEFAULTzbox);
00126 exit(1);
00127 }
00128 if ((s = strrchr( argv[0], '\\')))
00129 strcpy (command, s+1);
00130 else
00131 strcpy (command, argv[0]);
00132 if ((s= strstr (command, ".EXE"))
00133 || (s= strstr (command, ".exe")))
00134 *s= '\0';
00135
00136 for (i=1; i < argc; i++) {
00137 if (strlen (command) + strlen(argv[i]) + 1 < sizeof(command) ) {
00138 strcat (command, " ");
00139 strcat (command, argv[i]);
00140 }
00141 if (isdigit (argv[i][0])) {
00142 numpoints= atoi (argv[i]);
00143 continue;
00144 }
00145 if (argv[i][0] == '-')
00146 (argv[i])++;
00147 switch (argv[i][0]) {
00148 case 'c':
00149 addcube= 1;
00150 if (i+1 < argc && argv[i+1][0] == 'G')
00151 cube= (double) atof (&argv[++i][1]);
00152 break;
00153 case 'd':
00154 adddiamond= 1;
00155 if (i+1 < argc && argv[i+1][0] == 'G')
00156 diamond= (double) atof (&argv[++i][1]);
00157 break;
00158 case 'h':
00159 iscdd= 1;
00160 break;
00161 case 'l':
00162 isspiral= 1;
00163 break;
00164 case 'n':
00165 NOcommand= 1;
00166 break;
00167 case 'r':
00168 isregular= 1;
00169 break;
00170 case 's':
00171 issphere= 1;
00172 break;
00173 case 't':
00174 istime= 1;
00175 if (isdigit (argv[i][1]))
00176 seed= atoi (&argv[i][1]);
00177 else {
00178 seed= time (&timedata);
00179 sprintf (seedbuf, "%d", seed);
00180 strcat (command, seedbuf);
00181 }
00182 break;
00183 case 'x':
00184 issimplex= 1;
00185 break;
00186 case 'y':
00187 issimplex2= 1;
00188 break;
00189 case 'z':
00190 isinteger= 1;
00191 break;
00192 case 'B':
00193 box= (double) atof (&argv[i][1]);
00194 isbox= 1;
00195 break;
00196 case 'D':
00197 dim= atoi (&argv[i][1]);
00198 if (dim < 1
00199 || dim > MAXdim) {
00200 fprintf (stderr, "rbox error: dim %d too large or too small\n", dim);
00201 exit (1);
00202 }
00203 break;
00204 case 'G':
00205 if (argv[i][1])
00206 gap= (double) atof (&argv[i][1]);
00207 else
00208 gap= 0.5;
00209 isgap= 1;
00210 break;
00211 case 'L':
00212 if (argv[i][1])
00213 radius= (double) atof (&argv[i][1]);
00214 else
00215 radius= 10;
00216 islens= 1;
00217 break;
00218 case 'O':
00219 out_offset= (double) atof (&argv[i][1]);
00220 break;
00221 case 'P':
00222 addpoints++;
00223 break;
00224 case 'W':
00225 width= (double) atof (&argv[i][1]);
00226 iswidth= 1;
00227 break;
00228 case 'Z':
00229 if (argv[i][1])
00230 radius= (double) atof (&argv[i][1]);
00231 else
00232 radius= 1.0;
00233 isaxis= 1;
00234 break;
00235 default:
00236 fprintf (stderr, "rbox warning: unknown flag %s.\nExecute 'rbox' without arguments for documentation.\n", argv[i]);
00237 }
00238 }
00239
00240 if (isinteger && !isbox)
00241 box= DEFAULTzbox;
00242 if (addcube) {
00243 cubesize= floor(ldexp(1.0,dim)+0.5);
00244 if (cube == 0.0)
00245 cube= box;
00246 }else
00247 cubesize= 0;
00248 if (adddiamond) {
00249 diamondsize= 2*dim;
00250 if (diamond == 0.0)
00251 diamond= box;
00252 }else
00253 diamondsize= 0;
00254 if (islens) {
00255 if (isaxis) {
00256 fprintf (stderr, "rbox error: can not combine 'Ln' with 'Zn'\n");
00257 exit(1);
00258 }
00259 if (radius <= 1.0) {
00260 fprintf (stderr, "rbox error: lens radius %.2g should be greater than 1.0\n",
00261 radius);
00262 exit(1);
00263 }
00264 lensangle= asin (1.0/radius);
00265 lensbase= radius * cos (lensangle);
00266 }
00267 if (!numpoints) {
00268 if (issimplex2)
00269 ;
00270 else if (isregular + issimplex + islens + issphere + isaxis + isspiral + iswidth) {
00271 fprintf (stderr, "rbox error: missing count\n");
00272 exit(1);
00273 }else if (adddiamond + addcube + addpoints)
00274 ;
00275 else {
00276 numpoints= 50;
00277 issphere= 1;
00278 }
00279 }
00280 fp= stdout;
00281
00282 if (issimplex)
00283 totpoints= numpoints;
00284 else if (issimplex2)
00285 totpoints= numpoints+dim+1;
00286 else if (isregular) {
00287 totpoints= numpoints;
00288 if (dim == 2) {
00289 if (islens)
00290 totpoints += numpoints - 2;
00291 }else if (dim == 3) {
00292 if (islens)
00293 totpoints += 2 * numpoints;
00294 else if (isgap)
00295 totpoints += 1 + numpoints;
00296 else
00297 totpoints += 2;
00298 }
00299 }else
00300 totpoints= numpoints + isaxis;
00301 totpoints += cubesize + diamondsize + addpoints;
00302 if (iscdd)
00303 fprintf(fp, "%s\nbegin\n %d %d %s\n",
00304 NOcommand ? "" : command,
00305 totpoints, dim+1,
00306 isinteger ? "integer" : "real");
00307 else if (NOcommand)
00308 fprintf(fp, "%d\n%d\n", dim, totpoints);
00309 else
00310 fprintf(fp, "%d %s\n%d\n", dim, command, totpoints);
00311
00312 if (istime == 0) {
00313 for (s=command; *s; s++) {
00314 if (issimplex2 && *s == 'y')
00315 i= 'x';
00316 else
00317 i= *s;
00318 seed= 11*seed + i;
00319 }
00320 }
00321 qh_RANDOMseed_(seed);
00322
00323 for (i=1; i < argc; i++) {
00324 if (argv[i][0] == 'P') {
00325 s= argv[i]+1;
00326 count= 0;
00327 if (iscdd)
00328 out1( 1.0);
00329 while (*s) {
00330 out1( strtod (s, &s));
00331 count++;
00332 if (*s) {
00333 if (*s++ != ',') {
00334 fprintf (stderr, "rbox error: missing comma after coordinate in %s\n\n", argv[i]);
00335 exit (1);
00336 }
00337 }
00338 }
00339 if (count < dim) {
00340 for (k= dim-count; k--; )
00341 out1( 0.0);
00342 }else if (count > dim) {
00343 fprintf (stderr, "rbox error: %d coordinates instead of %d coordinates in %s\n\n",
00344 count, dim, argv[i]);
00345 exit (1);
00346 }
00347 fprintf (fp, "\n");
00348 }
00349 }
00350
00351 if (issimplex+issimplex2) {
00352 if (!(simplex= malloc( dim * (dim+1) * sizeof(double)))) {
00353 fprintf (stderr, "insufficient memory for simplex\n");
00354 exit(0);
00355 }
00356 simplexp= simplex;
00357 if (isregular) {
00358 for (i= 0; i<dim; i++) {
00359 for (k= 0; k<dim; k++)
00360 *(simplexp++)= i==k ? 1.0 : 0.0;
00361 }
00362 for (k= 0; k<dim; k++)
00363 *(simplexp++)= -1.0;
00364 }else {
00365 for (i= 0; i<dim+1; i++) {
00366 for (k= 0; k<dim; k++) {
00367 randr= qh_RANDOMint;
00368 *(simplexp++)= 2.0 * randr/randmax - 1.0;
00369 }
00370 }
00371 }
00372 if (issimplex2) {
00373 simplexp= simplex;
00374 for (i= 0; i<dim+1; i++) {
00375 if (iscdd)
00376 out1( 1.0);
00377 for (k= 0; k<dim; k++)
00378 out1( *(simplexp++) * box);
00379 fprintf (fp, "\n");
00380 }
00381 }
00382 for (j= 0; j<numpoints; j++) {
00383 if (iswidth)
00384 apex= qh_RANDOMint % (dim+1);
00385 else
00386 apex= -1;
00387 for (k= 0; k<dim; k++)
00388 coord[k]= 0.0;
00389 norm= 0.0;
00390 for (i= 0; i<dim+1; i++) {
00391 randr= qh_RANDOMint;
00392 factor= randr/randmax;
00393 if (i == apex)
00394 factor *= width;
00395 norm += factor;
00396 for (k= 0; k<dim; k++) {
00397 simplexp= simplex + i*dim + k;
00398 coord[k] += factor * (*simplexp);
00399 }
00400 }
00401 for (k= 0; k<dim; k++)
00402 coord[k] /= norm;
00403 if (iscdd)
00404 out1( 1.0);
00405 for (k=0; k < dim; k++)
00406 out1( coord[k] * box);
00407 fprintf (fp, "\n");
00408 }
00409 isregular= 0;
00410 numpoints= 0;
00411 }
00412
00413 if (isregular && !islens) {
00414 if (dim != 2 && dim != 3) {
00415 fprintf(stderr, "rbox error: regular points can be used only in 2-d and 3-d\n\n");
00416 exit(1);
00417 }
00418 if (!isaxis || radius == 0.0) {
00419 isaxis= 1;
00420 radius= 1.0;
00421 }
00422 if (dim == 3) {
00423 if (iscdd)
00424 out1( 1.0);
00425 out3n( 0.0, 0.0, -box);
00426 if (!isgap) {
00427 if (iscdd)
00428 out1( 1.0);
00429 out3n( 0.0, 0.0, box);
00430 }
00431 }
00432 angle= 0.0;
00433 anglediff= 2.0 * PI/numpoints;
00434 for (i=0; i < numpoints; i++) {
00435 angle += anglediff;
00436 x= radius * cos (angle);
00437 y= radius * sin (angle);
00438 if (dim == 2) {
00439 if (iscdd)
00440 out1( 1.0);
00441 out2n( x*box, y*box);
00442 }else {
00443 norm= sqrt (1.0 + x*x + y*y);
00444 if (iscdd)
00445 out1( 1.0);
00446 out3n( box*x/norm, box*y/norm, box/norm);
00447 if (isgap) {
00448 x *= 1-gap;
00449 y *= 1-gap;
00450 norm= sqrt (1.0 + x*x + y*y);
00451 if (iscdd)
00452 out1( 1.0);
00453 out3n( box*x/norm, box*y/norm, box/norm);
00454 }
00455 }
00456 }
00457 if (iscdd)
00458 fprintf (fp, "end\nhull\n");
00459 return 0;
00460 }
00461
00462 if (isregular && islens && dim == 2) {
00463 double cos_0;
00464
00465 angle= lensangle;
00466 anglediff= 2 * lensangle/(numpoints - 1);
00467 cos_0= cos (lensangle);
00468 for (i=0; i < numpoints; i++, angle -= anglediff) {
00469 x= radius * sin (angle);
00470 y= radius * (cos (angle) - cos_0);
00471 if (iscdd)
00472 out1( 1.0);
00473 out2n( x*box, y*box);
00474 if (i != 0 && i != numpoints - 1) {
00475 if (iscdd)
00476 out1( 1.0);
00477 out2n( x*box, -y*box);
00478 }
00479 }
00480 if (iscdd)
00481 fprintf (fp, "end\nhull\n");
00482 return 0;
00483 }
00484
00485 if (isregular && islens && dim != 2) {
00486 if (dim != 3) {
00487 fprintf(stderr, "rbox error: regular points can be used only in 2-d and 3-d\n\n");
00488 exit(1);
00489 }
00490 angle= 0.0;
00491 anglediff= 2* PI/numpoints;
00492 if (!isgap) {
00493 isgap= 1;
00494 gap= 0.5;
00495 }
00496 offset= sqrt (radius * radius - (1-gap)*(1-gap)) - lensbase;
00497 for (i=0; i < numpoints; i++, angle += anglediff) {
00498 x= cos (angle);
00499 y= sin (angle);
00500 if (iscdd)
00501 out1( 1.0);
00502 out3n( box*x, box*y, 0);
00503 x *= 1-gap;
00504 y *= 1-gap;
00505 if (iscdd)
00506 out1( 1.0);
00507 out3n( box*x, box*y, box * offset);
00508 if (iscdd)
00509 out1( 1.0);
00510 out3n( box*x, box*y, -box * offset);
00511 }
00512 if (iscdd)
00513 fprintf (fp, "end\nhull\n");
00514 return 0;
00515 }
00516
00517 if (isaxis) {
00518 gendim= dim-1;
00519 if (iscdd)
00520 out1( 1.0);
00521 for (j=0; j < gendim; j++)
00522 out1( 0.0);
00523 out1( -box);
00524 fprintf (fp, "\n");
00525 }else if (islens)
00526 gendim= dim-1;
00527 else
00528 gendim= dim;
00529
00530 for (i=0; i < numpoints; i++) {
00531 norm= 0.0;
00532 for (j=0; j < gendim; j++) {
00533 randr= qh_RANDOMint;
00534 coord[j]= 2.0 * randr/randmax - 1.0;
00535 norm += coord[j] * coord[j];
00536 }
00537 norm= sqrt (norm);
00538
00539 if (isaxis) {
00540 if (!isgap) {
00541 isgap= 1;
00542 gap= 1.0;
00543 }
00544 randr= qh_RANDOMint;
00545 rangap= 1.0 - gap * randr/randmax;
00546 factor= radius * rangap / norm;
00547 for (j=0; j<gendim; j++)
00548 coord[j]= factor * coord[j];
00549
00550 }else if (islens && issphere) {
00551 if (!isgap) {
00552 isgap= 1;
00553 gap= 1.0;
00554 }
00555 randr= qh_RANDOMint;
00556 rangap= 1.0 - gap * randr/randmax;
00557 factor= rangap / norm;
00558 for (j=0; j<gendim; j++)
00559 coord[j]= factor * coord[j];
00560
00561 }else if (islens && !issphere) {
00562 if (!isgap) {
00563 isgap= 1;
00564 gap= 1.0;
00565 }
00566 j= qh_RANDOMint % gendim;
00567 if (coord[j] < 0)
00568 coord[j]= -1.0 - coord[j] * gap;
00569 else
00570 coord[j]= 1.0 - coord[j] * gap;
00571
00572 }else if (isspiral) {
00573 if (dim != 3) {
00574 fprintf(stderr, "rbox error: spiral distribution is available only in 3d\n\n");
00575 exit(1);
00576 }
00577 coord[0]= cos(2*PI*i/(numpoints - 1));
00578 coord[1]= sin(2*PI*i/(numpoints - 1));
00579 coord[2]= 2.0*(double)i/(double)(numpoints-1) - 1.0;
00580
00581 }else if (issphere) {
00582 factor= 1.0/norm;
00583 if (iswidth) {
00584 randr= qh_RANDOMint;
00585 factor *= 1.0 - width * randr/randmax;
00586 }
00587 for (j=0; j<dim; j++)
00588 coord[j]= factor * coord[j];
00589 }
00590
00591 if (isaxis && issphere) {
00592 coord[dim-1]= 1.0;
00593 norm= 1.0;
00594 for (j=0; j<gendim; j++)
00595 norm += coord[j] * coord[j];
00596 norm= sqrt (norm);
00597 for (j=0; j<dim; j++)
00598 coord[j]= coord[j] / norm;
00599 if (iswidth) {
00600 randr= qh_RANDOMint;
00601 coord[dim-1] *= 1 - width * randr/randmax;
00602 }
00603
00604 }else if (isaxis && !issphere) {
00605 randr= qh_RANDOMint;
00606 coord[dim-1]= 2.0 * randr/randmax - 1.0;
00607
00608 }else if (islens) {
00609 coord[dim-1]= lensbase;
00610 for (j=0, norm= 0; j<dim; j++)
00611 norm += coord[j] * coord[j];
00612 norm= sqrt (norm);
00613 for (j=0; j<dim; j++)
00614 coord[j]= coord[j] * radius/ norm;
00615 coord[dim-1] -= lensbase;
00616 if (iswidth) {
00617 randr= qh_RANDOMint;
00618 coord[dim-1] *= 1 - width * randr/randmax;
00619 }
00620 if (qh_RANDOMint > randmax/2)
00621 coord[dim-1]= -coord[dim-1];
00622
00623 }else if (iswidth && !issphere) {
00624 j= qh_RANDOMint % gendim;
00625 if (coord[j] < 0)
00626 coord[j]= -1.0 - coord[j] * width;
00627 else
00628 coord[j]= 1.0 - coord[j] * width;
00629 }
00630
00631 if (iscdd)
00632 out1( 1.0);
00633 for (k=0; k < dim; k++)
00634 out1( coord[k] * box);
00635 fprintf (fp, "\n");
00636 }
00637
00638 if (addcube) {
00639 for (j=0; j<cubesize; j++) {
00640 if (iscdd)
00641 out1( 1.0);
00642 for (k=dim-1; k>=0; k--) {
00643 if (j & ( 1 << k))
00644 out1( cube);
00645 else
00646 out1( -cube);
00647 }
00648 fprintf (fp, "\n");
00649 }
00650 }
00651
00652 if (adddiamond) {
00653 for (j=0; j<diamondsize; j++) {
00654 if (iscdd)
00655 out1( 1.0);
00656 for (k=dim-1; k>=0; k--) {
00657 if (j/2 != k)
00658 out1( 0.0);
00659 else if (j & 0x1)
00660 out1( diamond);
00661 else
00662 out1( -diamond);
00663 }
00664 fprintf (fp, "\n");
00665 }
00666 }
00667 if (iscdd)
00668 fprintf (fp, "end\nhull\n");
00669 return 0;
00670 }
00671
00672
00673
00674
00675 int roundi( double a) {
00676 if (a < 0.0) {
00677 if (a - 0.5 < INT_MIN) {
00678 fprintf(stderr, "rbox input error: coordinate %2.2g is too large. Reduce 'Bn'\n", a);
00679 exit (1);
00680 }
00681 return a - 0.5;
00682 }else {
00683 if (a + 0.5 > INT_MAX) {
00684 fprintf(stderr, "rbox input error: coordinate %2.2g is too large. Reduce 'Bn'\n", a);
00685 exit (1);
00686 }
00687 return a + 0.5;
00688 }
00689 }
00690
00691 void out1(double a) {
00692
00693 if (isinteger)
00694 fprintf(fp, "%d ", roundi( a+out_offset));
00695 else
00696 fprintf(fp, qh_REAL_1, a+out_offset);
00697 }
00698
00699 void out2n( double a, double b) {
00700
00701 if (isinteger)
00702 fprintf(fp, "%d %d\n", roundi(a+out_offset), roundi(b+out_offset));
00703 else
00704 fprintf(fp, qh_REAL_2n, a+out_offset, b+out_offset);
00705 }
00706
00707 void out3n( double a, double b, double c) {
00708
00709 if (isinteger)
00710 fprintf(fp, "%d %d %d\n", roundi(a+out_offset), roundi(b+out_offset), roundi(c+out_offset));
00711 else
00712 fprintf(fp, qh_REAL_3n, a+out_offset, b+out_offset, c+out_offset);
00713 }
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724 static int seed = 1;
00725
00726 int qh_rand( void) {
00727 #define qh_rand_a 16807
00728 #define qh_rand_m 2147483647
00729 #define qh_rand_q 127773
00730 #define qh_rand_r 2836
00731 int lo, hi, test;
00732
00733 hi = seed / qh_rand_q;
00734 lo = seed % qh_rand_q;
00735 test = qh_rand_a * lo - qh_rand_r * hi;
00736 if (test > 0)
00737 seed= test;
00738 else
00739 seed= test + qh_rand_m;
00740 return seed;
00741 }
00742
00743 void qh_srand( int newseed) {
00744 if (newseed < 1)
00745 seed= 1;
00746 else if (newseed >= qh_rand_m)
00747 seed= qh_rand_m - 1;
00748 else
00749 seed= newseed;
00750 }
00751