sysbench icon indicating copy to clipboard operation
sysbench copied to clipboard

Add hexadecimal random support

Open davidducos opened this issue 4 years ago • 2 comments

Is it possible to add in: https://github.com/akopytov/sysbench/blob/805825fa81f633a7477f15ecdc152441e4ef4c83/src/sb_rand.c This code?

uint32_t sb_rand_hexadecimal(char *buf, uint32_t min_len, uint32_t max_len)
{
  unsigned int i;
  uint32_t num_chars;
  if (max_len == 0) {
    return 0; /* we can't be sure buf is long enough to populate, so be safe */
  }
  if (min_len > max_len)
  {
    min_len = 1;
  }

  num_chars = sb_rand_uniform(min_len, max_len);
  for (i=0; i < num_chars; i++)
  {
    buf[i] = sb_rand_uniform('0', 'f');
  }
  return num_chars;
}

And on https://github.com/akopytov/sysbench/blob/805825fa81f633a7477f15ecdc152441e4ef4c83/src/lua/internal/sysbench.rand.lua :

function sysbench.rand.hexadecimal(min_len, max_len)
   assert(min_len <= max_len)
   assert(max_len > 0)
   local buflen = max_len
   local buf = ffi.new("uint8_t[?]", buflen)
   local nchars = ffi.C.sb_rand_hexadecimal(buf, min_len, max_len)
   return ffi.string(buf, nchars)
end

davidducos avatar Sep 11 '20 16:09 davidducos

Duplicate of https://github.com/akopytov/sysbench/pull/214

davidducos avatar Sep 17 '20 15:09 davidducos

Sorry, similar, not the same, I still need the hexadecimal. I will create the PR shortly

davidducos avatar Sep 17 '20 15:09 davidducos