Skip to content

Generates random values with a specific hamming weight.

License

Notifications You must be signed in to change notification settings

dougives/weighted-rng

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

weighted-rng

Generates random values with a specific hamming weight.

A random 64-bit value (r) is drawn from /dev/urandom. If r does not have the specified weight, another value between 0-63 inclusive is drawn, which selects a bit position of r. If the weight of r is less than specified, the selected bit is or'ed with 1. If the weight of r is greater than specified, it is and'ed with 0. This process repeats until r has the specified weight.