# Problems understanding the applications of pseudo random number generators

I am trying to explore different methods used to generate pseudo-random numbers for my project in maths and I would be very grateful for some help or references to valuable sources as it is very hard to explore this field without background information.

Although the mechanism used to create PRNs are quite clear for me, I have problems understanding how they are really applied. I was wondering which algorithms I can use to generate a 4-digit code. When you generate such codes, do you always convert the generated numbers to bits? What tests do you use to check if the sequence of those 4-digit numbers is actually random?

Thanks a lot for help!

In most cases your runtime uses a DRBG rather than a PRNG. A DRBG is a Deterministic Random Bit Generator, so it delivers bits to the user rather than random numbers in a specific range. Generally it is possible to request bytes and then use - for instance - the lowest 4 bits. If the 8 bits of a byte are random then the lower 4 bits must be random as well after all. In most programming languages you can get to the lower 4 bits (4 bits is called a nibble) by MASKing: nibble = byte & 0x0F.
If you have a PRNG that delivers numbers in a range $$0$$ (inclusive) to $$n$$ (exclusive) then you can request a number in the range $$0$$ to $$16$$ because $$2^4=16$$. The number requested will have the lowest order bits set to the random values.