A
hardware random number generator (HW-RNG) and related method are disclosed. The HW- RNG comprises a sample generation stage, adapted to produce primary samples from a plurality of primitive probability distributions, a
sample processing stage and a
control unit. The sample generation stage includes sets of programmable p-bit devices, a
programming unit to adjust the mean values for each set of p-bit devices, and a distinct sampling circuit for each set of p-bit devices. The
sample processing stage comprises function logic blocks and selection circuitry configured to
route at least one subset of the primary samples to a corresponding function
logic block. The
control unit is configured to obtain information relating to a composition of basis distributions representative of a
target distribution, instruct the function
logic block to perform at least arithmetic operation identified by the information, instruct the
programming unit to program the sets of p-bit devices according to the composition of basis distributions, and generate the select
signal to operatively couple the function
logic block to
sampling circuits that produce primary samples of random variables defined by the composition of basis distributions.