\0 in rand bug fixed.