Skip to content

Instantly share code, notes, and snippets.

View camel-cdr's full-sized avatar

Camel Coder camel-cdr

  • 21:42 (UTC +02:00)
View GitHub Profile
@camel-cdr
camel-cdr / random.h
Last active March 5, 2021 21:48
How to generate unbiased uniform random floating-point numbers including all representable values. An excerpt from the random number library I'm currently developing.
/*
* 5.2 Uniform real distribution -----------------------------------------------
*
* Generating uniform random floating-point numbers might seem easy at first
* glance, just cast the output of a PRNG to the desired float type and divide
* by the biggest possible output of the PRNG to obtain a random float between
* 0 and 1 that can now be scaled up.
* Though as before this straightforward approach is biased.
*
* For the next part, I assume you are already acquainted with the IEEE 754