The relationship between bits and int/float random number generator


I want to figure out the relationship between bits and RNG for int or float.

(By <em>random</em> I mean uniformly distributed)

<hr />

I am given a <em>perfect</em> boolean random generator, and I am asked to implement a random 32 bits integer generator (including negative, zero and positive). What I want to do is <em>generate a random boolean for each of the 32 bits, and concat them together to be a random int</em>.

Am I doing the right thing?

<hr />

Also from the other way around, if I am given a <em>perfect</em> random 32 bits integer generator, can I say each bit can be considered as uniformly distributed over 0 and 1?

<hr />

how about float (not only between 0 and 1, but the full range of float)?

Can I use the same way to generate random IEEE 745 float?


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.

<hr />

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.

<hr />

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].


Yes. This is exactly what <a href="http://www.random.org/faq/#Q2.10" rel="nofollow">random.org</a> does. In this case, the domains are fairly easy to map across -- things like a <a href="http://mathforum.org/library/drmath/view/65653.html" rel="nofollow">6 sided die</a> are harder.


  • Geometry shader doesn't do anything when fed GL_POINTS
  • Avoiding try/catch hell in my web pages
  • web scrape with rvest
  • WebGL: Access buffer from shader
  • finding symmetric difference/unique elements in multiple arrays in javascript
  • Gruntfile.js - Throwing error 'Recursive process.nextTick detected\"
  • SQL Server 2008 R2 - Islands and Gaps [closed]
  • SQL Server: +(unary) operator on non-numeric Strings
  • model.get_weights() returning array of NaNs after training due to NaN masking
  • Crafting a LINQ based solution to determine if a set of predicates are satisfied for a pair of colle
  • Return to second to last URL in MVC (return View with previous filter conditions applied)?
  • Multiple flexboxes with margin-right, except the last one in the row? Without JS?
  • Best win32 compiled scripting language? [closed]
  • Problem in concatenation of objects in javascript
  • Efficient & Pythonic way of finding all possible sublists of a list in given range and the minim
  • can variables be set randomly when declaring them again?
  • Access user's phone number on iOS 7
  • SetWindowsHookEx does not react on media keys
  • Create Instant using a negative year
  • uniform generation of points on 3D box
  • Unable to decode certificate at client new X509Certificate2()
  • Excel's Macro-Recorder usage
  • print() is showing quotation marks in results
  • Make VS2015 use angular-cli ng at build time in a .NET project
  • Allowing both email and username for authentication
  • Android fill_parent issue
  • Get one-time binding to work for ng-if
  • Get object from AWS S3 as a stream
  • How to add a column to a Pandas dataframe made of arrays of the n-preceding values of another column
  • How to handle AllServersUnavailable Exception
  • htaccess rewriting URLs with multiple forward slashes
  • Weird JavaScript statement, what does it mean?
  • VBA Convert delimiter text file to Excel
  • How do you troubleshoot character encoding problems?
  • How to format a variable of double type
  • Why joiner is not used after Sequence generator or Update statergy
  • Django query for large number of relationships
  • Reading document lines to the user (python)
  • How to Embed XSL into XML
  • Android Heatmap on canvas or ImageView