2 * Copyright (C) 2006-2009 Brian Aker
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
12 #include "libmemcached/common.h"
19 #include "generator.h"
21 /* Use this for string generation */
22 static const char ALPHANUMERICS
[]=
23 "0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";
25 #define ALPHANUMERICS_SIZE (sizeof(ALPHANUMERICS)-1)
27 static size_t get_alpha_num(void)
29 return (size_t)random() % ALPHANUMERICS_SIZE
;
32 static void get_random_string(char *buffer
, size_t size
)
34 char *buffer_ptr
= buffer
;
37 *buffer_ptr
++= ALPHANUMERICS
[get_alpha_num()];
38 *buffer_ptr
++= ALPHANUMERICS
[get_alpha_num()];
41 void pairs_free(pairs_st
*pairs
)
48 /* We free until we hit the null pair we stores during creation */
49 for (x
= 0; pairs
[x
].key
; x
++)
58 pairs_st
*pairs_generate(uint64_t number_of
, size_t value_length
)
63 pairs
= (pairs_st
*)calloc((size_t)number_of
+ 1, sizeof(pairs_st
));
68 for (x
= 0; x
< number_of
; x
++)
70 pairs
[x
].key
= (char *)calloc(100, sizeof(char));
73 get_random_string(pairs
[x
].key
, 100);
74 pairs
[x
].key_length
= 100;
76 pairs
[x
].value
= (char *)calloc(value_length
, sizeof(char));
79 get_random_string(pairs
[x
].value
, value_length
);
80 pairs
[x
].value_length
= value_length
;
85 fprintf(stderr
, "Memory Allocation failure in pairs_generate.\n");