-2
AUDIO_FILES = [
    os.path.join(settings.AUDIO_FILES_DIR, "1.mp3"),
    os.path.join(settings.AUDIO_FILES_DIR, "2.mp3"),
    os.path.join(settings.AUDIO_FILES_DIR, "3.mp3"),
    os.path.join(settings.AUDIO_FILES_DIR, "4.mp3"),
    os.path.join(settings.AUDIO_FILES_DIR, "5.mp3"),
]

def _get_audio_clip():
    audio_file = random.choice(AUDIO_FILES)
    audio_clip = AudioFileClip(audio_file)
    return audio_clip

_get_audio_clip()

Can anyone point out why random.choice always returns first value of the list in this piece of code?

NVM
  • 5,442
  • 4
  • 41
  • 61

1 Answers1

0

This answered my question. Quoting the answer:

What happens is that on Unix every worker process inherits the same state of the random number generator from the parent process. This is why they generate identical pseudo-random sequences.

Using random.seed() in the worker process solved the problem.

NVM
  • 5,442
  • 4
  • 41
  • 61