I am looking for a lightweight (< 500 SLOC) random generator that's suitable for cryptography. This needs to be C code that I can include in the SlipRock library (which I am developing). Currently I use libsodium but it seems a shame to pull in such a (relatively) massive dependency, and conversations with potential users indicate that they would not want such a large dependency. I am looking for something that I can include in my project.

At the same time, I don't want to write something myself. This is crypto code, and so the usual “don't roll your own crypto” maxim applies. Right now I am just planning to take some code from libsodium, but I would rather use a standalone library.


1 Answer 1


libsodium's default implementation fits in a single, (currently) 371 lines of C code.

See the randombytes/sysrandom/randombytes_sysrandom.c file.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.