SHARE
TWEET

Untitled

a guest Aug 20th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unsigned long long int random_word(size_t n, size_t m)
  2.      
  3. # b = size of integer type
  4. # n = number of set bits
  5. # random_limited(x) is some function returning [0, x) sufficiently uniformly
  6. def random_n_set_bits(b, n):
  7.     assert b > 0
  8.     assert n >= 0 and n <= b
  9.     result = 0
  10.     available = list(range(b))
  11.     for i in range(n):
  12.         index = random_limited(len(available))
  13.         bit = available[index]
  14.         available = available[:index] + available[index + 1:]
  15.         result |= (1 << bit)
  16.     return result
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top