Pick a random number between 0 and n using a constant source of randomness
x86 machines with rdrand instruction, 10 bytes

BITS 64

_try_again:

 rdrand eax
jnc _try_again

 cmp eax, edi
ja _try_again

 ret


machine code

0FC7F0 73FB 39F8 77F7 C3




The input is in the register rdi and the output in rax.
This respects the SYS V AMD64 ABI so the code effectively implement a C function 

unsigned int foo(unsigned int max); 


with 32-bit ints.

The instruction rdrand is described by Intel


  RDRAND returns random numbers that are supplied by a cryptographically secure, deterministic random bit generator DRBG. The DRBG is designed to meet the NIST SP 800-90A standard.


Dealing with CSRNG it is implicit that the distribution is uniform, anyway, quoting the NIST SP 800-90A:


  A random number is an instance of an unbiased random variable,
  that is, the output produced by a uniformly distributed random process.




The procedure generates a random number and if it is non-strictly greater than the input it is returned.
Otherwise, the process is reiterated.  

Since eax is 32-bit, rdrand returns a number between 0 and 232-1, so for every n in [0, 232-1] the number of expected iterations is 232/(n+1) which is defined for all n in [0, 230).