-3

I am working in an application which is a online examination application. Now at first the students has to login and they will get the questions. Now what i want is when the students login then a random no. must be generated between 1 to 50. And that will extract 50 questions for him. How to generate the random number between 1 to 50 when the login is successful.

This is my html code:

<body>
<h3>Login Form</h3>
<form id="form1" name="form1" method="post" action="login.php">
  Student Username: 
  <label>
  <input type="text" name="username" id="username" />
  </label>
  <p>Student Password: 
    <label>
    <input type="text" name="password" id="password" />
    </label>
  </p>
  <p>
    <label>
    <input type="submit" name="button" id="button" value="login" />
    </label>
  </p>
</form>
</body>

Now when the login is successful then a random no. between 1 to 50 must be generated.

TJHeuvel
  • 12,403
  • 4
  • 37
  • 46
Nyaro
  • 177
  • 3
  • 7
  • 23
  • [mt_rand(1,50)](http://www.php.net/manual/en/function.mt-rand.php) – Jon Sep 07 '11 at 08:45
  • possible duplicate of [Random number within range with a seed](http://stackoverflow.com/questions/6208141/random-number-within-range-with-a-seed) And I don't understand why include your login form? What is your real objective? How single random number can use to determine 50 questions? – ajreal Sep 07 '11 at 08:48
  • 1
    Possible duplicate of [PHP random string generator](http://stackoverflow.com/questions/4356289/php-random-string-generator) – Nyaro Oct 14 '15 at 00:23

1 Answers1

7

if i understand you, you need to use rand [docs] or mt_rand [docs] functions like:

rand(1, 50);
Haim Evgi
  • 123,187
  • 45
  • 217
  • 223
  • As documented here: http://nl3.php.net/manual/en/function.rand.php – TJHeuvel Sep 07 '11 at 08:45
  • 1
    Or if you want better randomness use `mt_random(min,max)`, see: http://www.php.net/manual/en/function.mt-rand.php, see: http://www.random.org/analysis/ for some of the problems with php's `rand` – Johan Sep 07 '11 at 08:46
  • actually i know this is a simple question but i have a lot to do after that which i am not getting to express.sorry – Nyaro Sep 07 '11 at 08:50