It looks to me that this will not work for one major reason.
variable i is assigned to the function random_num() so every time ' i ' is called so is the function, which means that there is a 50% chance that it could play a song that is not precached.