瀏覽代碼

Add a convenience macro to get a fast one-in-n calculation

Nick Mathewson 6 年之前
父節點
當前提交
97b9dfe305
共有 1 個文件被更改,包括 3 次插入0 次删除
  1. 3 0
      src/lib/crypt_ops/crypto_rand.h

+ 3 - 0
src/lib/crypt_ops/crypto_rand.h

@@ -68,6 +68,9 @@ unsigned crypto_fast_rng_get_uint(crypto_fast_rng_t *rng, unsigned limit);
 uint64_t crypto_fast_rng_get_uint64(crypto_fast_rng_t *rng, uint64_t limit);
 double crypto_fast_rng_get_double(crypto_fast_rng_t *rng);
 
+#define crypto_fast_rng_one_in_n(rng, n)        \
+  (0 == (crypto_fast_rng_get_uint((rng), (n))))
+
 crypto_fast_rng_t *get_thread_fast_rng(void);
 
 #ifdef CRYPTO_PRIVATE