"Invalid delay_until randomness number '%s'", p);
request->failed = TRUE;
} else {
- extra_secs = rand() % extra_secs;
+ extra_secs = i_rand() % extra_secs;
}
}
if (str_to_time(value, ×tamp) < 0) {
o_stream_nsend(output, data, size);
i_stream_skip(input, size);
- if (rand() % 3 == 0 && conn->to_delay == NULL) {
+ if (i_rand() % 3 == 0 && conn->to_delay == NULL) {
conn->to_delay =
- timeout_add(rand() % DIRECTOR_CONN_MAX_DELAY_MSECS,
+ timeout_add(i_rand() % DIRECTOR_CONN_MAX_DELAY_MSECS,
director_connection_timeout, conn);
io_remove(&conn->in_io);
io_remove(&conn->out_io);
return;
hosts = array_get(&hosts_array, &count);
- i = rand() % count;
+ i = i_rand() % count;
- hosts[i]->vhost_count = (rand() % 20) * 10;
+ hosts[i]->vhost_count = (i_rand() % 20) * 10;
admin_send(conn, t_strdup_printf("HOST-SET\t%s\t%u\n",
net_ip2addr(&hosts[i]->ip), hosts[i]->vhost_count));
count++;
if (count != 0) {
- i = 0; count = rand() % count;
+ i = 0; count = i_rand() % count;
for (conn = director_connections; i < count; conn = conn->next) {
i_assert(conn != NULL);
i++;
admin_read_hosts(admin);
to_disconnect =
- timeout_add(1000*(5 + rand()%DIRECTOR_DISCONNECT_TIMEOUT_SECS),
+ timeout_add(1000*(5 + i_rand()%DIRECTOR_DISCONNECT_TIMEOUT_SECS),
director_connection_disconnect_timeout, (void *)NULL);
}
struct user_directory *dir;
struct mail_host *host = t_new(struct mail_host, 1);
time_t timestamp;
- unsigned int i, count = 10000 + rand()%10000;
+ unsigned int i, count = 10000 + i_rand()%10000;
test_begin("user directory random");
dir = user_directory_init(USER_DIR_TIMEOUT, NULL);
for (i = 0; i < count; i++) {
- if (rand() % 10 == 0)
+ if (i_rand() % 10 == 0)
timestamp = ioloop_time;
else
- timestamp = ioloop_time-rand()%100;
+ timestamp = ioloop_time-i_rand()%100;
(void)user_directory_add(dir, i+1, host, timestamp);
}
verify_user_directory(dir, count);
random_node_create(struct dsync_mailbox_tree *tree, unsigned int counter,
const char *name)
{
- return node_create(tree, counter, name, rand() % 10);
+ return node_create(tree, counter, name, i_rand() % 10);
}
static void nodes_create(struct dsync_mailbox_tree *tree, unsigned int *counter,
create_random_nodes(struct dsync_mailbox_tree *tree, const char *parent_name,
unsigned int depth, unsigned int *counter)
{
- unsigned int parent_len, i, nodes_count = 1 + rand() % 3;
+ unsigned int parent_len, i, nodes_count = 1 + i_rand() % 3;
string_t *str;
if (depth == MAX_DEPTH)
/* 3) write semi-compressible data */
for (i = 0; i < sizeof(buf); i++) {
- if (rand () % 3 == 0)
- buf[i] = rand() % 4;
+ if (i_rand() % 3 == 0)
+ buf[i] = i_rand() % 4;
else
buf[i] = i;
}
i_fatal("dict_init(%s) failed: %s", argv[1], error);
for (i = 0;; i++) {
- i_snprintf(key, sizeof(key), "%s/%02x", prefix, rand() % 0xff);
- i_snprintf(value, sizeof(value), "%04x", rand() % 0xffff);
- switch (rand() % 4) {
+ i_snprintf(key, sizeof(key), "%s/%02x", prefix, i_rand() % 0xff);
+ i_snprintf(value, sizeof(value), "%04x", i_rand() % 0xffff);
+ switch (i_rand() % 4) {
case 0:
pending++;
dict_lookup_async(dict, key, lookup_callback, NULL);
if (fs->op_probability[op] == 0)
return FALSE;
- if ((unsigned int)(rand() % (100*divider)) <= fs->op_probability[op]) {
+ if ((unsigned int)(i_rand() % (100*divider)) <= fs->op_probability[op]) {
errno = EIO;
fs_set_error(_fs, RANDOMFAIL_ERROR);
return TRUE;
if (!fs_random_fail(_fs, 1, op))
return FALSE;
*offset_r = fs->range_start[op] +
- rand() % (fs->range_end[op] - fs->range_start[op] + 1);
+ i_rand() % (fs->range_end[op] - fs->range_start[op] + 1);
return TRUE;
}
/* test input in random chunks */
outi = first_outi;
for (i = 0; i < input_len; i += char_len) {
- max = rand() % (input_len - i) + 1;
+ max = i_rand() % (input_len - i) + 1;
for (char_len = 0; char_len < max; )
char_len += uni_utf8_char_bytes(input[i+char_len]);
while (fts_tokenizer_next(tok, input+i, char_len, &token, &error) > 0) {
for (i = 0; i < 10000; i++) T_BEGIN {
for (unsigned int j = 0; j < sizeof(addr); j++)
- addr[j] = test_chars[rand() % N_ELEMENTS(test_chars)];
+ addr[j] = test_chars[i_rand() % N_ELEMENTS(test_chars)];
str_truncate(str, 0);
(void)uni_utf8_get_valid_data(addr, sizeof(addr), str);
while (fts_tokenizer_next(tok, str_data(str), str_len(str),
flags = t_new(enum mail_flags, hdr.messages_count + 1);
for (r = 0; r < 1000; r++) {
- change = rand() % (MAIL_FLAGS_NONRECENT+1);
- seq1 = (rand() % hdr.messages_count) + 1;
+ change = i_rand() % (MAIL_FLAGS_NONRECENT+1);
+ seq1 = (i_rand() % hdr.messages_count) + 1;
seq2 = seq1 == hdr.messages_count ? seq1 :
- (rand() % (hdr.messages_count - seq1)) + seq1;
+ (i_rand() % (hdr.messages_count - seq1)) + seq1;
- switch (rand() % 3) {
+ switch (i_rand() % 3) {
case 0:
modify_type = MODIFY_ADD;
for (seq = seq1; seq <= seq2; seq++)
test_assert(MODSEQ_MATCH(2, next_offset));
/* do some random testing with cache */
for (unsigned int i = 0; i < LOG_FILE_MODSEQ_CACHE_SIZE*10; i++) {
- modseq = (rand() % max_modseq) + 1;
+ modseq = (i_rand() % max_modseq) + 1;
test_assert(mail_transaction_log_file_get_modseq_next_offset(file, modseq, &next_offset) == 0);
test_assert(MODSEQ_MATCH(modseq, next_offset));
}
test_assert(modseq == max_modseq);
/* do some random testing with cache */
for (unsigned int i = 0; i < LOG_FILE_MODSEQ_CACHE_SIZE*10; i++) {
- modseq = (rand() % max_modseq) + 1;
+ modseq = (i_rand() % max_modseq) + 1;
test_assert(mail_transaction_log_file_get_highest_modseq_at(file, modseq_next_offset[modseq], &modseq_at, &error) == 0);
test_assert(modseq_at == modseq);
test_assert(mail_transaction_log_file_get_highest_modseq_at(file, modseq_alt_next_offset[modseq], &modseq_at, &error) == 0);
unsigned int i;
for (i = 0; i < count; i++)
- str_append_c(dest, rand() % ('z'-'a'+1) + 'a');
+ str_append_c(dest, i_rand() % ('z'-'a'+1) + 'a');
}
static void ATTR_NULL(3)
ht = mail_html2text_init(0);
for (unsigned int i = 0; i < 100; i++) {
- s[0] = valid_chars[rand() % N_ELEMENTS(valid_chars)];
- s[1] = valid_chars[rand() % N_ELEMENTS(valid_chars)];
- mail_html2text_more(ht, s, rand()%2+1, str);
+ s[0] = valid_chars[i_rand() % N_ELEMENTS(valid_chars)];
+ s[1] = valid_chars[i_rand() % N_ELEMENTS(valid_chars)];
+ mail_html2text_more(ht, s, i_rand()%2+1, str);
}
mail_html2text_deinit(&ht);
str_truncate(str, 0);
/* fill only with 7bit data so we don't have to worry about
the data being valid UTF-8 */
for (j = 0; j < sizeof(buf); j++)
- buf[j] = rand() % 128;
- buflen = rand() % sizeof(buf);
+ buf[j] = i_rand() % 128;
+ buflen = i_rand() % sizeof(buf);
str_truncate(encoded, 0);
str_truncate(decoded, 0);
for (unsigned int j = 0; j < input_len; ) {
const unsigned char *input_part =
(const unsigned char *)tests[i].input + j;
- unsigned int len = rand() % (input_len - j) + 1;
+ unsigned int len = i_rand() % (input_len - j) + 1;
message_header_hash_more(&ctx, &hash_method_md5,
&md5_ctx, tests[i].version,
input_part, len);
auth->refcount = 1;
auth->fd = -1;
hash_table_create_direct(&auth->requests, pool, 0);
- auth->id_counter = (rand() % 32767) * 131072U;
+ auth->id_counter = (i_rand() % 32767) * 131072U;
return auth;
}
const struct setting_parser_context *parser;
const char *error;
- output.used_local = output.service_uses_local && (rand() % 2) != 0;
+ output.used_local = output.service_uses_local && (i_rand() % 2) != 0;
if (output.used_local) {
input.local_ip.family = AF_INET;
- input.local_ip.u.ip4.s_addr = 100 + rand() % 100;
+ input.local_ip.u.ip4.s_addr = 100 + i_rand() % 100;
}
- output.used_remote = output.service_uses_remote && (rand() % 2) != 0;
+ output.used_remote = output.service_uses_remote && (i_rand() % 2) != 0;
if (output.used_remote) {
input.remote_ip.family = AF_INET;
- input.remote_ip.u.ip4.s_addr = 100 + rand() % 100;
+ input.remote_ip.u.ip4.s_addr = 100 + i_rand() % 100;
}
test_assert(master_service_settings_cache_read(cache, &input, NULL, &parser, &error) == 0);
}
#endif
/* 0.1 .. 0.2msec */
-#define LOCK_RANDOM_USLEEP_TIME (100000 + (unsigned int)rand() % 100000)
+#define LOCK_RANDOM_USLEEP_TIME (100000 + (unsigned int)i_rand() % 100000)
enum mbox_lock_type {
MBOX_LOCK_DOTLOCK,
} else {
/* copy data to a buffer in somewhat random place. this could
help catch bugs. */
- new_skip_diff = rand() % 128;
+ new_skip_diff = i_rand() % 128;
stream->skip = (stream->skip - tstream->skip_diff) +
new_skip_diff;
stream->pos = (stream->pos - tstream->skip_diff) +
#define DEFAULT_LOCK_SUFFIX ".lock"
/* 0.1 .. 0.2msec */
-#define LOCK_RANDOM_USLEEP_TIME (100000 + (unsigned int)rand() % 100000)
+#define LOCK_RANDOM_USLEEP_TIME (100000 + (unsigned int)i_rand() % 100000)
/* Maximum 3 second wait between dotlock checks */
#define LOCK_MAX_WAIT_USECS (1000000 * 3)
break;
/* busy. wait for a while. */
- usleep(((rand() % 10) + 1) * 10000);
+ usleep(((i_rand() % 10) + 1) * 10000);
if (gettimeofday(&now, NULL) < 0)
i_panic("gettimeofday() failed: %m");
} while (timeval_diff_msecs(&now, &start) < (int)msecs);
}
}
for (i = 0; i < 1000; i++)
- array_swap(&foos[rand()%3], &foos[rand()%3]);
+ array_swap(&foos[i_rand()%3], &foos[i_rand()%3]);
/* Just want size 3, 5, and 7 in any order */
test_assert(array_count(&foos[0]) * array_count(&foos[1]) * array_count(&foos[2]) == 3*5*7);
test_assert(array_count(&foos[0]) + array_count(&foos[1]) + array_count(&foos[2]) == 3+5+7);
t_array_init(&arr1, NELEMS);
t_array_init(&arr2, NELEMS);
for (i = 0; i < NELEMS; i++) {
- elems[i] = rand();
+ elems[i] = i_rand();
array_append(&arr2, &elems[i], 1);
}
array_append(&arr1, elems, NELEMS);
test_assert(array_equal_fn_ctx(&arr1, &arr2, test_compare_ushort_fuzz, &fuzz) == TRUE);
for (i = 0; i < 256; i++) {
- unsigned int j = rand() % NELEMS;
+ unsigned int j = i_rand() % NELEMS;
const unsigned short *ptmp = array_idx(&arr2, j);
unsigned short tmp = *ptmp;
- unsigned short repl = tmp + deltas[rand() % N_ELEMENTS(deltas)];
+ unsigned short repl = tmp + deltas[i_rand() % N_ELEMENTS(deltas)];
array_idx_set(&arr2, j, &repl);
test_assert_idx(array_cmp(&arr1, &arr2) == (tmp == repl), i);
t_array_init(&arr1, NELEMS);
t_array_init(&arr2, NELEMS);
for (i = 0; i < NELEMS; i++) {
- elemstrs[i] = t_strdup_printf("%x", rand()); /* never 0-length */
+ elemstrs[i] = t_strdup_printf("%x", i_rand()); /* never 0-length */
array_append(&arr2, &elemstrs[i], 1);
}
array_append(&arr1, elemstrs, NELEMS);
test_assert(array_cmp(&arr1, &arr2) == TRUE); /* pointers shared, so identical */
test_assert(array_equal_fn(&arr1, &arr2, test_compare_string) == TRUE); /* therefore value same */
for (i = 0; i < 2560; i++) {
- unsigned int j = rand() % NELEMS;
+ unsigned int j = i_rand() % NELEMS;
const char *const *ostr_p = array_idx(&arr2, j);
const char *ostr = *ostr_p;
unsigned int olen = strlen(ostr);
- unsigned int rc = rand() % (olen + 1);
+ unsigned int rc = i_rand() % (olen + 1);
char ochar = ostr[rc];
char buf[12];
const char *bufp = buf;
memcpy(buf, ostr, olen+1);
- buf[rc] = rand() % (CHAR_MAX + 1 - CHAR_MIN) + CHAR_MIN;
+ buf[rc] = i_rand() % (CHAR_MAX + 1 - CHAR_MIN) + CHAR_MIN;
if(rc == olen)
buf[rc+1] = '\0';
array_idx_set(&arr2, j, &bufp);
test_begin("padded base32 encode/decode with random input");
for (i = 0; i < 1000; i++) {
- max = rand() % sizeof(buf);
+ max = i_rand() % sizeof(buf);
for (j = 0; j < max; j++)
- buf[j] = rand();
+ buf[j] = i_rand();
str_truncate(str, 0);
str_truncate(dest, 0);
test_begin("padded base32hex encode/decode with random input");
for (i = 0; i < 1000; i++) {
- max = rand() % sizeof(buf);
+ max = i_rand() % sizeof(buf);
for (j = 0; j < max; j++)
- buf[j] = rand();
+ buf[j] = i_rand();
str_truncate(str, 0);
str_truncate(dest, 0);
test_begin("base64 encode/decode with random input");
for (i = 0; i < 1000; i++) {
- max = rand() % sizeof(buf);
+ max = i_rand() % sizeof(buf);
for (j = 0; j < max; j++)
- buf[j] = rand();
+ buf[j] = i_rand();
str_truncate(str, 0);
str_truncate(dest, 0);
buf = buffer_create_dynamic(default_pool, 1);
for (i = 0; i < BUF_TEST_SIZE; i++)
- testdata[i] = rand();
+ testdata[i] = i_rand();
memset(shadowbuf, 0, sizeof(shadowbuf));
shadowbuf_size = 0;
for (i = 0; i < BUF_TEST_COUNT; i++) {
if (buf->used == BUF_TEST_SIZE) {
- size = shadowbuf_size = rand() % (buf->used - 1);
+ size = shadowbuf_size = i_rand() % (buf->used - 1);
buffer_set_used_size(buf, size);
memset(shadowbuf + shadowbuf_size, 0,
BUF_TEST_SIZE - shadowbuf_size);
i_assert(buf->used < BUF_TEST_SIZE);
}
- test = rand() % 6;
- zero = rand() % 10 == 0;
+ test = i_rand() % 6;
+ zero = i_rand() % 10 == 0;
switch (test) {
case 0:
- pos = rand() % (BUF_TEST_SIZE-1);
- size = rand() % (BUF_TEST_SIZE - pos);
+ pos = i_rand() % (BUF_TEST_SIZE-1);
+ size = i_rand() % (BUF_TEST_SIZE - pos);
if (!zero) {
buffer_write(buf, pos, testdata, size);
memcpy(shadowbuf + pos, testdata, size);
shadowbuf_size = pos + size;
break;
case 1:
- size = rand() % (BUF_TEST_SIZE - buf->used);
+ size = i_rand() % (BUF_TEST_SIZE - buf->used);
if (!zero) {
buffer_append(buf, testdata, size);
memcpy(shadowbuf + shadowbuf_size,
shadowbuf_size += size;
break;
case 2:
- pos = rand() % (BUF_TEST_SIZE-1);
- size = rand() % (BUF_TEST_SIZE - I_MAX(buf->used, pos));
+ pos = i_rand() % (BUF_TEST_SIZE-1);
+ size = i_rand() % (BUF_TEST_SIZE - I_MAX(buf->used, pos));
if (!zero) {
buffer_insert(buf, pos, testdata, size);
memmove(shadowbuf + pos + size,
shadowbuf_size = pos + size;
break;
case 3:
- pos = rand() % (BUF_TEST_SIZE-1);
- size = rand() % (BUF_TEST_SIZE - pos);
+ pos = i_rand() % (BUF_TEST_SIZE-1);
+ size = i_rand() % (BUF_TEST_SIZE - pos);
buffer_delete(buf, pos, size);
if (pos < shadowbuf_size) {
if (pos + size > shadowbuf_size)
case 4:
if (shadowbuf_size <= 1)
break;
- pos = rand() % (shadowbuf_size-1); /* dest */
- pos2 = rand() % (shadowbuf_size-1); /* source */
- size = rand() % (shadowbuf_size - I_MAX(pos, pos2));
+ pos = i_rand() % (shadowbuf_size-1); /* dest */
+ pos2 = i_rand() % (shadowbuf_size-1); /* source */
+ size = i_rand() % (shadowbuf_size - I_MAX(pos, pos2));
buffer_copy(buf, pos, buf, pos2, size);
memmove(shadowbuf + pos,
shadowbuf + pos2, size);
shadowbuf_size = pos + size;
break;
case 5:
- pos = rand() % (BUF_TEST_SIZE-1);
- size = rand() % (BUF_TEST_SIZE - pos);
+ pos = i_rand() % (BUF_TEST_SIZE-1);
+ size = i_rand() % (BUF_TEST_SIZE - pos);
p = buffer_get_space_unsafe(buf, pos, size);
memcpy(p, testdata, size);
memcpy(shadowbuf + pos, testdata, size);
T_BEGIN {
size_t bigleft = t_get_bytes_available();
size_t i;
- for (i = 1; i < bigleft-64; i += rand()%32) T_BEGIN {
+ for (i = 1; i < bigleft-64; i += i_rand()%32) T_BEGIN {
unsigned char *p, *p2;
size_t left;
t_malloc_no0(i);
test_begin("data-stack recursive");
for(i = 0; i < count; i++) T_BEGIN {
- int number=rand()%100+50;
- int size=rand()%100+50;
+ int number=i_rand()%100+50;
+ int size=i_rand()%100+50;
test_ds_recurse(depth, number, size);
} T_END;
test_end();
keys = i_new(unsigned int, KEYMAX); keyidx = 0;
hash_table_create_direct(&hash, pool, 0);
for (i = 0; i < KEYMAX; i++) {
- key = (rand() % KEYMAX) + 1;
- if (rand() % 5 > 0) {
+ key = (i_rand() % KEYMAX) + 1;
+ if (i_rand() % 5 > 0) {
if (hash_table_lookup(hash, POINTER_CAST(key)) == NULL) {
hash_table_insert(hash, POINTER_CAST(key),
POINTER_CAST(1));
keys[keyidx++] = key;
}
} else if (keyidx > 0) {
- delidx = rand() % keyidx;
+ delidx = i_rand() % keyidx;
hash_table_remove(hash, POINTER_CAST(keys[delidx]));
memmove(&keys[delidx], &keys[delidx+1],
(keyidx-delidx-1) * sizeof(*keys));
size_t size = 0;
unsigned int i, j, offset, stream_count, data_len, simult;
- stream_count = (rand() % TEST_MAX_ISTREAM_COUNT) + 2;
+ stream_count = (i_rand() % TEST_MAX_ISTREAM_COUNT) + 2;
streams = t_new(struct istream *, stream_count + 1);
for (i = 0, offset = 0; i < stream_count; i++) {
- data_len = rand() % TEST_MAX_ISTREAM_SIZE + 1;
+ data_len = i_rand() % TEST_MAX_ISTREAM_SIZE + 1;
w_data = t_malloc_no0(data_len);
for (j = 0; j < data_len; j++)
w_data[j] = offset++;
concat = i_stream_create_concat(streams);
i_stream_set_max_buffer_size(concat, TEST_MAX_BUFFER_SIZE);
- simult = rand() % TEST_MAX_ISTREAM_COUNT;
+ simult = i_rand() % TEST_MAX_ISTREAM_COUNT;
if (simult > 0) {
limits = t_new(struct istream *, simult);
for (i = 0; i < simult; i++)
}
for (i = 0; i < 1000; i++) {
- struct istream *input = (simult == 0) ? concat : limits[rand() % simult];
- if (rand() % 3 == 0) {
- i_stream_seek(input, rand() % offset);
+ struct istream *input = (simult == 0) ? concat : limits[i_rand() % simult];
+ if (i_rand() % 3 == 0) {
+ i_stream_seek(input, i_rand() % offset);
} else {
ssize_t ret = i_stream_read(input);
size = i_stream_get_data_size(input);
} else if (input->v_offset + size != offset) {
test_assert(ret > 0);
test_assert(input->v_offset + ret <= offset);
- i_stream_skip(input, rand() % ret);
+ i_stream_skip(input, i_rand() % ret);
data = i_stream_get_data(input, &size);
for (j = 0; j < size; j++) {
char buf[100];
size_t len = 0;
while (len < sizeof(buf) - 1) {
- switch(rand()%16) {
+ switch(i_rand()%16) {
case 0: goto outahere;
case 1: buf[len] = '\r'; break;
case 2: buf[len] = '\n'; break;
size_t size;
unsigned int i, j, offset, stream_count, data_len, buffer_size;
- stream_count = (rand() % 10) + 2;
+ stream_count = (i_rand() % 10) + 2;
streams = t_new(struct istream *, stream_count + 1);
for (i = 0, offset = 0; i < stream_count; i++) {
- data_len = rand() % 100 + 1;
+ data_len = i_rand() % 100 + 1;
w_data = t_malloc_no0(data_len);
for (j = 0; j < data_len; j++)
w_data[j] = offset++;
streams[i] = NULL;
i_assert(offset > 0);
- buffer_size = (rand() % 100) + 1; size = 0;
+ buffer_size = (i_rand() % 100) + 1; size = 0;
input = i_stream_create_seekable(streams, buffer_size, fd_callback, NULL);
/* first read it through */
i_stream_seek(input, 0);
for (i = 0; i < 100; i++) {
- if (rand() % 3 == 0) {
- i_stream_seek(input, rand() % offset);
+ if (i_rand() % 3 == 0) {
+ i_stream_seek(input, i_rand() % offset);
} else {
ssize_t ret = i_stream_read(input);
if (input->v_offset + size == offset)
} else {
test_assert(ret > 0);
test_assert(input->v_offset + ret <= offset);
- i_stream_skip(input, rand() % (ret+1));
+ i_stream_skip(input, i_rand() % (ret+1));
data = i_stream_get_data(input, &size);
for (j = 0; j < size; j++) {
test_assert_idx(i_stream_read(child_input[i]) == 0, len);
test_assert_idx(!tee_i_stream_child_is_waiting(child_input[i]), len);
}
- delta = rand() % 32; /* may stand still */
+ delta = i_rand() % 32; /* may stand still */
if(delta > TEST_BUF_SIZE - len)
delta = 1;
}
delta = 1;
while ((len += delta) <= TEST_STR_LEN) {
- unsigned int lagger = rand() % CHILD_COUNT;
+ unsigned int lagger = i_rand() % CHILD_COUNT;
test_istream_set_size(test_input, len);
for (i = 0; i < CHILD_COUNT; i++) {
test_assert(i_stream_read(child_input[i]) == -2);
test_assert(i_stream_read(child_input[i]) == -2);
test_assert(!tee_i_stream_child_is_waiting(child_input[i]));
}
- delta = rand() % 31 + 1; /* mustn't stand still */
+ delta = i_rand() % 31 + 1; /* mustn't stand still */
if(delta > TEST_STR_LEN - len)
delta = 1;
}
output = o_stream_create_buffer(buffer);
o_stream_cork(output);
- size = (rand() % MAX_BUFSIZE) + 1;
+ size = (i_rand() % MAX_BUFSIZE) + 1;
random_fill_weak(randbuf, size);
memcpy(buf, randbuf, size);
test_assert(o_stream_send(output, buf, size) > 0);
for (i = 0; i < 10; i++) {
- offset = rand() % (MAX_BUFSIZE*3);
- size = (rand() % MAX_BUFSIZE) + 1;
+ offset = i_rand() % (MAX_BUFSIZE*3);
+ size = (i_rand() % MAX_BUFSIZE) + 1;
random_fill_weak(randbuf, size);
memcpy(buf + offset, randbuf, size);
test_assert(o_stream_pwrite(output, randbuf, size, offset) == 0);
- if (rand() % 10 == 0)
+ if (i_rand() % 10 == 0)
test_assert(o_stream_flush(output) > 0);
}
output = o_stream_create_fd(fd, MAX_BUFSIZE);
o_stream_cork(output);
- size = (rand() % MAX_BUFSIZE) + 1;
+ size = (i_rand() % MAX_BUFSIZE) + 1;
random_fill_weak(randbuf, size);
memcpy(buf, randbuf, size);
test_assert(o_stream_send(output, buf, size) > 0);
for (i = 0; i < 10; i++) {
- offset = rand() % (MAX_BUFSIZE*3);
- size = (rand() % MAX_BUFSIZE) + 1;
+ offset = i_rand() % (MAX_BUFSIZE*3);
+ size = (i_rand() % MAX_BUFSIZE) + 1;
random_fill_weak(randbuf, size);
memcpy(buf + offset, randbuf, size);
test_assert(o_stream_pwrite(output, randbuf, size, offset) == 0);
- if (rand() % 10 == 0)
+ if (i_rand() % 10 == 0)
test_assert(o_stream_flush(output) > 0);
}
for (i = 0; i < 100; i++) {
pq = priorityq_init(cmp_int, 1);
for (j = 0; j < PQ_MAX_ITEMS; j++) {
- items[j].num = rand();
+ items[j].num = i_rand() % INT_MAX;
priorityq_add(pq, &items[j].item);
}
for (j = 0; j < PQ_MAX_ITEMS; j++) {
- if (rand() % 3 == 0) {
+ if (i_rand() % 3 == 0) {
priorityq_remove(pq, &items[j].item);
items[j].num = -1;
}
i_array_init(&range, 1);
memset(shadowbuf, 0, sizeof(shadowbuf));
for (i = 0; i < SEQ_RANGE_TEST_COUNT; i++) {
- seq1 = rand() % SEQ_RANGE_TEST_BUFSIZE;
- seq2 = seq1 + rand() % (SEQ_RANGE_TEST_BUFSIZE - seq1);
- test = rand() % 4;
+ seq1 = i_rand() % SEQ_RANGE_TEST_BUFSIZE;
+ seq2 = seq1 + i_rand() % (SEQ_RANGE_TEST_BUFSIZE - seq1);
+ test = i_rand() % 4;
switch (test) {
case 0:
ret = seq_range_array_add(&range, seq1) ? 0 : 1; /* FALSE == added */
static void test_str_to_uintmax(void)
{
unsigned int i=0;
- int randrange = rand()%15+1; /* when 1, will max out on 1s */
- uintmax_t value = 0, valbase = rand() * 1000ull;
+ int randrange = i_rand()%15+1; /* when 1, will max out on 1s */
+ uintmax_t value = 0, valbase = i_rand() * 1000ull;
int len, ret;
char buff[50]; /* totally assumes < 159 bits */
value = (value << 1) + 1;
if (value >= 64)
- value -= rand()%randrange; /* don't always test the same numbers */
+ value -= i_rand()%randrange; /* don't always test the same numbers */
len = crappy_uintmax_to_str(buff, value);
ret = str_to_uintmax(buff, &value_back);
test_assert_idx(ret == 0, i);
static void test_str_to_uintmax_hex(void)
{
unsigned int i=0;
- int randrange = rand()%15+1; /* when 1, will max out on 1s */
- uintmax_t value = 0, valbase = rand() * 1000ull;
+ int randrange = i_rand()%15+1; /* when 1, will max out on 1s */
+ uintmax_t value = 0, valbase = i_rand() * 1000ull;
int len, ret;
char buff[52]; /* totally assumes < 200 bits */
value = (value << 1) + 1;
if (value >= 64)
- value -= rand()%randrange; /* don't always test the same numbers */
+ value -= i_rand()%randrange; /* don't always test the same numbers */
len = crappy_uintmax_to_str_hex(buff, value);
ret = str_to_uintmax_hex(buff, &value_back);
test_assert_idx(ret == 0, i);
static void test_str_to_uintmax_oct(void)
{
unsigned int i=0;
- int randrange = rand()%15+1; /* when 1, will max out on 1s */
- uintmax_t value = 0, valbase = rand() * 1000ull;
+ int randrange = i_rand()%15+1; /* when 1, will max out on 1s */
+ uintmax_t value = 0, valbase = i_rand() * 1000ull;
int len, ret;
char buff[69]; /* totally assumes < 200 bits */
value = (value << 1) + 1;
if (value >= 64)
- value -= rand()%randrange; /* don't always test the same numbers */
+ value -= i_rand()%randrange; /* don't always test the same numbers */
len = crappy_uintmax_to_str_oct(buff, value);
ret = str_to_uintmax_oct(buff, &value_back);
test_assert_idx(ret == 0, i);
/* The bottom 6 bits should be irrelevant to code coverage,
only test 000000, 111111, and something in between. */
if ((chr & 63) == 1)
- chr += rand() % 62; /* After 0, somewhere between 1 and 62 */
+ chr += i_rand() % 62; /* After 0, somewhere between 1 and 62 */
else if ((chr & 63) > 0 && (chr & 63) < 63)
chr |= 63; /* After random, straight to 63 */
unsigned int count = timing->count;
unsigned int idx;
if (count > RAND_MAX >> 6)
- idx = (rand()*((uint64_t)RAND_MAX+1) + rand()) % count;
+ idx = (i_rand()*((uint64_t)RAND_MAX+1) + i_rand()) % count;
else
- idx = rand() % count;
+ idx = i_rand() % count;
if (idx < TIMING_SUBSAMPLING_BUFFER)
timing->samples[idx] = usecs;
}
processes will disconnect at slightly different times to
spread the load. */
timeval_add_msecs(&rec->disconnect_timestamp,
- rand() % PROXY_DISCONNECT_INTERVAL_MSECS);
+ i_rand() % PROXY_DISCONNECT_INTERVAL_MSECS);
}
rec->num_disconnects_since_ts++;
if (proxy->to != NULL) {
/* randomize the initial index in case service_count=1
(although in that case it's unlikely this setting is
even used..) */
- login_source_ips_idx = rand() % login_source_ips_count;
+ login_source_ips_idx = i_rand() % login_source_ips_count;
}
login_load_modules();
if (to_instance != NULL)
timeout_remove(&to_instance);
- to_instance = timeout_add((3600*12 + rand()%(60*30)) * 1000,
+ to_instance = timeout_add((3600*12 + i_rand()%(60*30)) * 1000,
instance_update_now, list);
}
signal to all of them at once */
process->to_idle =
timeout_add((service->idle_kill * 1000) +
- (rand() % 100)*10,
+ (i_rand() % 100)*10,
service_process_kill_idle,
process);
}