Replace rand() with SecureRandom.random_number()