1
/*<html><pre> -<a href="index.htm#TOC"
2
>-------------------------------</a><a name="TOP">-</a>
5
Park & Miller's minimimal standard random number generator
14
#ifdef _MSC_VER /* Microsoft Visual C++ -- warning level 4 */
15
#pragma warning( disable : 4706) /* assignment within conditional function */
16
#pragma warning( disable : 4996) /* function was declared deprecated(strcpy, localtime, etc.) */
19
/*-<a href="qh-globa.htm#TOC"
20
>-------------------------------</a><a name="argv_to_command">-</a>
22
qh_argv_to_command( argc, argv, command, max_size )
24
build command from argc/argv
28
a space-delimited string of options (just as typed)
29
returns false if max_size is too short
33
makes option string easy to input and output
34
matches qh_argv_to_command_size()
38
int qh_argv_to_command(int argc, char *argv[], char* command, int max_size) {
41
*command= '\0'; /* max_size > 0 */
44
if ((s= strrchr( argv[0], '\\')) /* get filename w/o .exe extension */
45
|| (s= strrchr( argv[0], '/')))
49
if ((int)strlen(s) < max_size) /* WARN64 */
53
if ((s= strstr(command, ".EXE"))
54
|| (s= strstr(command, ".exe")))
57
for (i=1; i < argc; i++) {
59
remaining= max_size - (int)strlen(command) - (int)strlen(s) - 2; /* WARN64 */
60
if (!*s || strchr(s, ' ')) {
61
char *t= command + strlen(command);
78
}else if (remaining < 0) {
87
qh_fprintf(qh ferr, 6033, "qhull input error: more than %d characters in command line\n",
90
} /* argv_to_command */
92
/*-<a href="qh-globa.htm#TOC"
93
>-------------------------------</a><a name="argv_to_command_size">-</a>
95
qh_argv_to_command_size( argc, argv )
97
return size to allocate for qh_argv_to_command()
101
actual size is usually shorter
103
int qh_argv_to_command_size(int argc, char *argv[]) {
104
unsigned int count= 1; /* null-terminator if argc==0 */
108
for (i=0; i<argc; i++){
109
count += (int)strlen(argv[i]) + 1; /* WARN64 */
110
if (i>0 && strchr(argv[i], ' ')) {
111
count += 2; /* quote delimiters */
112
for (s=argv[i]; *s; s++) {
120
} /* argv_to_command_size */
122
/*-<a href="qh-geom.htm#TOC"
123
>-------------------------------</a><a name="rand">-</a>
127
generate pseudo-random number between 1 and 2^31 -2
130
For qhull and rbox, called from qh_RANDOMint(),etc. [user.h]
132
From Park & Miller's minimal standard random number generator
133
Communications of the ACM, 31:1192-1201, 1988.
134
Does not use 0 or 2^31 -1
135
this is silently enforced by qh_srand()
136
Can make 'Rn' much faster by moving qh_rand to qh_distplane
139
/* Global variables and constants */
141
int qh_rand_seed= 1; /* define as global variable instead of using qh */
143
#define qh_rand_a 16807
144
#define qh_rand_m 2147483647
145
#define qh_rand_q 127773 /* m div a */
146
#define qh_rand_r 2836 /* m mod a */
150
int seed = qh_rand_seed;
152
hi = seed / qh_rand_q; /* seed div q */
153
lo = seed % qh_rand_q; /* seed mod q */
154
test = qh_rand_a * lo - qh_rand_r * hi;
158
seed= test + qh_rand_m;
160
/* seed = seed < qh_RANDOMmax/2 ? 0 : qh_RANDOMmax; for testing */
161
/* seed = qh_RANDOMmax; for testing */
165
void qh_srand( int seed) {
168
else if (seed >= qh_rand_m)
169
qh_rand_seed= qh_rand_m - 1;
174
/*-<a href="qh-geom.htm#TOC"
175
>-------------------------------</a><a name="randomfactor">-</a>
177
qh_randomfactor( scale, offset )
178
return a random factor r * scale + offset
181
qh.RANDOMa/b are defined in global.c
183
realT qh_randomfactor(realT scale, realT offset) {
187
return randr * scale + offset;
190
/*-<a href="qh-geom.htm#TOC"
191
>-------------------------------</a><a name="randommatrix">-</a>
193
qh_randommatrix( buffer, dim, rows )
194
generate a random dim X dim matrix in range [-1,1]
195
assumes buffer is [dim+1, dim]
198
sets buffer to random numbers
199
sets rows to rows of buffer
200
sets row[dim] as scratch row
202
void qh_randommatrix(realT *buffer, int dim, realT **rows) {
204
realT **rowi, *coord, realr;
208
for (i=0; i < dim; i++) {
210
for (k=0; k < dim; k++) {
212
*(coord++)= 2.0 * realr/(qh_RANDOMmax+1) - 1.0;
218
/*-<a href="qh-globa.htm#TOC"
219
>-------------------------------</a><a name="strtol">-</a>
221
qh_strtol( s, endp) qh_strtod( s, endp)
222
internal versions of strtol() and strtod()
223
does not skip trailing spaces
225
some implementations of strtol()/strtod() skip trailing spaces
227
double qh_strtod(const char *s, char **endp) {
230
result= strtod(s, endp);
231
if (s < (*endp) && (*endp)[-1] == ' ')
236
int qh_strtol(const char *s, char **endp) {
239
result= (int) strtol(s, endp, 10); /* WARN64 */
240
if (s< (*endp) && (*endp)[-1] == ' ')