Obligatory "How To Safely Generate A Random Number" link[1] that I always wind up posting in threads like these. There's also the getrandom syscall[2] which uses the /dev/urandom pool.
[1] http://sockpuppet.org/blog/2014/02/25/safely-generate-random...