How to generate 6 digit random number based on current date & time
<p>what logic i can use to generate 6 digit random number based on current date and time. suppose i want to generate a 6 digit random number which will be valid up to 5 second. after 5 second if anyone input that random number into system then system will say it is expire. one thing i need to mention that there will be no database interaction. i don't want to generate random number and store it in database table. 5 second validity logic will be embedded in generated random number as a result i can validate it later that whether it is generate before 5 sec or not. </p>

<p>i asked this question in another forum and they gave me code to generate  6 digit random number based on current date and time like</p>

<pre><code>var random = new Random(System.DateTime.Now.Millisecond);
int randomNumber = random.Next(1, 500000);
</code></pre>

<p>is it ok? because i am not advance developer.if i can generate 6 digit random number using the above logic then later how can i determine programatically that the number was generate before 5 sec or not. basically i need two routine one for generating 6 digit random number based on current date &amp; time and another routine will check that generated number was generated before 5 sec or not.</p>

<p>please guide me with concept and code. thanks</p>
