Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

random module needs convenience functions #11

Open
nemequ opened this issue Mar 23, 2017 · 1 comment
Open

random module needs convenience functions #11

nemequ opened this issue Mar 23, 2017 · 1 comment

Comments

@nemequ
Copy link
Owner

nemequ commented Mar 23, 2017

µnit has some, like munit_rand_int_range. @jibsen, IIRC you did some work on those functions, would you mind if I relicensed them to public domain (CC0) and merged them into psnip?

It would probably also be a good idea to provide psnip_random_int, psnip_random_double… Ideally I'd like to just have a macro like

#define psnip_random_value(source, T) \
  ({ T psinp_random__tmp; \
     psnip_random_bytes(src, sizeof(T), &tmp); \
     psnip_random__tmp;  })

But that's a GCC extension; IIRC clang and icc support it, but I don't think there is a way to implement it with MSVC. I think the best we'll be able to do is something like

#define PSNIP_RANDOM_DEFINE_VALUE_FUNC(T, func_name) \
  __attribute__((__unused__)) \
  static inline T func_name (enum PSnipRandomSource source) { \
    T tmpval_; \
    psnip_random_bytes(source, sizeof(T), &tmpval_); \
    return tmpval_; \
  }

PSNIP_RANDOM_DEFINE_VALUE_FUNC(char, psnip_random_char)
PSNIP_RANDOM_DEFINE_VALUE_FUNC(short, psnip_random_short)
PSNIP_RANDOM_DEFINE_VALUE_FUNC(int, psnip_random_int)
...

With appropriate macros for the unused attribute and the inline keyword, of course.

@jibsen
Copy link

jibsen commented Mar 24, 2017

µnit has some, like munit_rand_int_range. @jibsen, IIRC you did some work on those functions, would you mind if I relicensed them to public domain (CC0) and merged them into psnip?

Please feel free to do that (but we should probably resolve nemequ/munit#30 first).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants