3
* routines needed for the tpcc loading and transaction programs
14
static int nums[CUST_PER_DIST];
15
static int perm_count;
17
void SetSeed (int seed)
23
* return number uniformly distributed b/w min and max, inclusive
25
int RandomNumber (int min, int max)
27
return min + (rand() % ((max - min) + 1));
31
* non uniform random -- see p. 15
33
* the constant C depends on which value of A is passed, but the same
34
* value of C should be used for all calls with the same value of
35
* A. however, we know in advance which values of A will be used.
37
int NURand (unsigned A, unsigned x, unsigned y)
40
unsigned C, C_255, C_1023, C_8191;
43
C_255 = RandomNumber(0, 255);
44
C_1023 = RandomNumber(0, 1023);
45
C_8191 = RandomNumber(0, 8191);
50
case 255: C = C_255; break;
51
case 1023: C = C_1023; break;
52
case 8191: C = C_8191; break;
55
"NURand: unexpected value (%d) of A used\n",
61
(((RandomNumber(0, A) | RandomNumber(x, y)) + C) % (y-x+1)) + x;
67
* make a ``random a-string'': a string of random alphanumeric
68
* characters of a random length of minimum x, maximum y, and
71
int MakeAlphaString (int x, int y, char str[])
73
static char *alphanum = "0123456789"
74
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
75
"abcdefghijklmnopqrstuvwxyz";
76
int arrmax = 61; /* index of last array element */
79
len = RandomNumber(x, y);
81
for (i = 0; i < len; i++)
82
str[i] = alphanum[RandomNumber(0, arrmax)];
88
* like MakeAlphaString, only numeric characters only
90
int MakeNumberString (int x, int y, char str[])
92
static char *numeric = "0123456789";
96
len = RandomNumber(x, y);
98
for (i = 0; i < len; i++)
99
str[i] = numeric[RandomNumber(0, arrmax)];
105
* turn system time into database format
106
* the format argument should be a strftime() format string that produces
107
* a datetime string acceptable to the database
109
void gettimestamp (char str[], char *format, size_t len)
115
datetime = localtime(&t);
117
if ( !strftime(str, len, format, datetime) ) {
118
fprintf(stderr, "error writing timestamp to string\n");
124
* permute the list of customer ids for the order table
126
void InitPermutation (void)
133
/* initialize with consecutive values [1..ORD_PER_DIST] */
134
for (i = 0, cur = nums; i < ORD_PER_DIST; i++, cur++) {
139
for (i = 0; i < ORD_PER_DIST-1; i++) {
140
j = (int)RandomNumber(i+1, ORD_PER_DIST-1);
141
swap_int(nums[i], nums[j]);
145
int GetPermutation (void)
147
if ( perm_count >= ORD_PER_DIST ) {
148
fprintf(stderr, "GetPermutation: past end of list!\n");
151
return nums[perm_count++];
154
/*==================================================================+
158
| TPC-C Lastname Function.
160
| num - non-uniform random number
161
| name - last name string
162
+==================================================================*/
163
void Lastname(num, name)
168
{"BAR", "OUGHT", "ABLE", "PRI", "PRES",
169
"ESE", "ANTI", "CALLY", "ATION", "EING"};
171
strcpy(name,n[num/100]);
172
strcat(name,n[(num/10)%10]);
173
strcat(name,n[num%10]);