]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add a convenience macro to get a fast one-in-n calculation
authorNick Mathewson <nickm@torproject.org>
Wed, 20 Feb 2019 17:21:05 +0000 (12:21 -0500)
committerNick Mathewson <nickm@torproject.org>
Wed, 20 Feb 2019 17:21:05 +0000 (12:21 -0500)
src/lib/crypt_ops/crypto_rand.h

index 6eef22ed4dd864309ac6461d95d6b7dd4fd8e85c..bb424fd69113929038dae4097d633dcf590d3555 100644 (file)
@@ -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