generate keys
| 247 | |
| 248 | // generate keys |
| 249 | static inline void init_random_keys(int *keys, int count, int seed) |
| 250 | { |
| 251 | int save_seed = time(NULL); |
| 252 | int *array = (int*)malloc(sizeof(int) * count); |
| 253 | int length = count, i; |
| 254 | xseed = seed; |
| 255 | for (i = 0; i < count; i++) { |
| 256 | array[i] = i; |
| 257 | } |
| 258 | for (i = 0; i < length; i++) { |
| 259 | int pos = xrand() % count; |
| 260 | int key = array[pos]; |
| 261 | keys[i] = key; |
| 262 | array[pos] = array[--count]; |
| 263 | } |
| 264 | free(array); |
| 265 | xseed = save_seed; |
| 266 | } |
| 267 | |
| 268 | // A utility function to swap to integers |
| 269 | static inline void swap (int *a, int *b) |