algorithm - How to create a uniform distribution over non-power-of-2 elements from n bits? -


Assuming that I can generate random bytes of data, I choose an element from an array of How can I use N Elements

If I have 256 elements then I can generate 1 byte of entropy (8 bits), and then select it for my element I can choose to convert to an integer.

If I have 2 elements, then I can generate 1 byte, I can leave 7 bit and use the remaining bit to select my element.

But what if I have 3 elements? 1 bit is very low and 2 is too much, how do I randomly select 1 of 3 elements with the same elements?

You can generate from the proper distribution, just lay down in the required range if you have N elements Generate random bits of roof (log) (n) = <. This is disabled, but still works until the bits are generated randomly

In your example where you have N = 3, you need at least K = 2 bit , You have the same likelihood [00, 01, 10, 11] the same probability. To map it to the appropriate category, ignore any one result, such as creating a new joint probability distribution on the last two bits, think of P (x_1, x_2), where P (x_1 = 1, x_2 = 1 ) = 0, while for every other, it will be 1/3 rehearsed (i.e., (1/4) / (3/4) = 1/3).


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -