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 &amp; 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.

Generally the conversion to nibbles should be covered by existing tests. However, if you still want to perform a test then you could try and generate about 500 billion nibbles (yes, you are reading that correctly) and use that to create a 250 GB file. That file can then be used to test against the Dieharder testing framework. Testing for randomness requires a lot of samples if you want to be cryptographically secure.

Beware that most DRBG's are actually (re-)seeeded using an operating system. You must make sure that the DRBGs/PRNGs actually delivers the type of pseudo-random stream you're after.