I was using the following code to generate sequence of pseudo-random numbers that was used for cryptographic purposes, but then I read somewhere that it may not be very secure.
Look at (or use) the random number generator in the OpenSSL library.
The hard part with any secure random number generator is the seeding. If you are on Windows, consider using rand_s(). On Linux look at /dev/urand.
Some seeding methods suffer from not being very random soon after a reboot. You can make a file with random bytes. Use the file and the OS method for seeding. Periodically use your random number generator to write a new file.