First of all javascript is running on a client side and php is running on a server side. It means you can't just store the generated number. But there is a workaround on that. You can do that by means of AJAX request.
In your js you can do this.
var res_id = your_random_number;
var res_level = your_random_number
$.post("/any/url/that/contains/your/php/code", {res_id:res_id, res_level:res_level});
In your php.
$_SESSION["res_id"] = $_POST["res_id"];
$_SESSION["res_level"] = $_POST["res_level"];