switch using random function