var num= sessionStorage.getItem("random"); if(!num|| num<=0){ num= parseInt(Math.random()* 10000000); } sessionStorage.setItem("random",num-100); $("selector").text(num);