Yes, you are indeed doing it right, using 32 draws of the different numbers, will give you a uniform distributed random variable.
Explanation: Each number can be generated by a unique combination of 32 0/1 draws. No 2 numbers are generated from the same combination, and no number is generated from 2 combinations - meaning, the probability for each number is 1/2^32 - as expected.
Yes, Same principle applies here. There are 2^32 'ways' to choose 32 bits number, and similarly to the previous question - you can see that the numbers are independently uniformly distributed on {0,1} per bit.
A random uniformly distributed float in range [0,1] can be generated by randUnsignedInt()/(2^32-1)
. An alternative is drawing an int
and just re-interpret it ad float - assuming both are using the same number of bits (basically - both are 32 bits number, they only vary in the way you interpret them...) Note that the alternative is NOT in range [0,1].