Reorganize randomness code