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.
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
++)
59 pairs_st
*pairs_generate(uint64_t number_of
, size_t value_length
)
64 pairs
= (pairs_st
*)calloc((size_t)number_of
+ 1, sizeof(pairs_st
));
69 for (x
= 0; x
< number_of
; x
++)
71 pairs
[x
].key
= (char *)calloc(100, sizeof(char));
74 get_random_string(pairs
[x
].key
, 100);
75 pairs
[x
].key_length
= 100;
79 pairs
[x
].value
= (char *)calloc(value_length
, sizeof(char));
82 get_random_string(pairs
[x
].value
, value_length
);
83 pairs
[x
].value_length
= value_length
;
88 pairs
[x
].value_length
= 0;
94 fprintf(stderr
, "Memory Allocation failure in pairs_generate.\n");