Improve function random_background