import audio, time, virtualtimers, random
from time import time

# Hopefully change the PRNG state a bit
random.seed(int( 1000000 * time() ) % 1000000)

# Making sure you can get away before the crickets are chricketing
print ('You have 10 seconds headstart... RUN!')

def randomise_next_run():
    global ms_until_chirp
    ms_until_chirp = random.randint(10, 120) * 1000
    print('The amazing crickets will play after: ', ms_until_chirp, ' milliseconds')

def play_chirps():
    global ms_until_chirp
    audio.play('/apps/digital_cricket/effects-crickets.mp3')
    randomise_next_run()
    return ms_until_chirp

randomise_next_run()
virtualtimers.begin(1000)
virtualtimers.new(ms_until_chirp, play_chirps)

# This cricket sound was proudly presented by Geluidsbord.nl!