How to keep the random value remain same in a session variable in php
<p>I am new in php and trying to solve a simple problem like create a random number and store it in session variable so that 
the value remain same for the entire session. I need to compare that value with user input from the same php page as below.</p>

<pre><code>&lt;?php 

    session_start();
    //get a random number and store it in session variable
    $_SESSION["random"] = rand(1,10); 
    $randomNumber = $_SESSION["random"];

    if (isset($_POST['submit'])) {

        $input = $_POST['input'];

        if( $input &gt; $randomNumber )
        {       
            //code
        }
        else if($input &lt; $randomNumber)
        {
            //code
        }

    }       
?&gt;


&lt;html&gt;
&lt;body&gt;
    &lt;form action="" method="post"&gt;
    &lt;label &gt; Enter input to match:&lt;/label&gt;&lt;br /&gt;
    &lt;input type="text" name="input" id="input" /&gt;&lt;br /&gt;&lt;br /&gt;
    &lt;input type="submit"  name="submit" value="Submit" /&gt;
    &lt;/form&gt;
&lt;/body&gt; 
&lt;/html&gt;
</code></pre>