Random number generator on HTML program - only select 5 out of1-100 and no dupilcates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jhernandy
    New Member
    • Sep 2010
    • 3

    Random number generator on HTML program - only select 5 out of1-100 and no dupilcates

    I have built a Table using HTML and would like to have a random number genereator, genereate numbers in each of the 5 boxes on the table with no duplicates between 1-50, I have a problem getting the numbers in each box on table, and creating no duplicate numbers - 3x5 square box

    Code:
    <table width="199" height="290" border="1">
    <tr>
          <td height="45"><div align="center">
            <h2><strong>T</strong></h2>
          </div></td>
          <td>&nbsp;</td>
          <td><div align="center"><a title= " prize 1">1</a></div></td>
          </tr>
        <tr>
          <td height="47"><div align="center">
            <h2><strong>A</strong></h2>
          </div></td>
          <td>&nbsp;</td>
          <td><div align="center"><atitle="prize 2">2</a></div>
          <div align="center"></div></td>
          </tr>
        <tr>
          <td height="53"><div align="center">
            <h2><strong>B</strong></h2>
          </div></td>
          <td>&nbsp;</td>
          <td><div align="center"><a title="prize 3">3</a></div></td>
          </tr>
        <tr>
          <td height="47"><div align="center">
    <h2><strong>L</strong></h2>
    </div></td>
          <td>&nbsp;</td>
          <td><div align="center"><a title="prize 4">4</a></div></td>
          </tr>
        <tr>
          <td height="53"><div align="center">
            <h2><strong>E</strong></h2>
          </div></td>
          <td>&nbsp;</td>
          <td><div align="center"><a title="prize 5">5</a></div></td>
          </tr>
    </table>
    <h3><strong>If your number appears in the square you win prizes 1-5</strong><br />
      </h3>
    I thought PHP would better, is C++ or Java better??
    Last edited by Dormilich; Sep 21 '10, 10:28 PM. Reason: please use [code] [/code] tags (#) when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    I see no benefit of one of the programming languages over the other, as long as your logic is correct.

    Comment

    • jhernandy
      New Member
      • Sep 2010
      • 3

      #3
      Help!! random number generator - HTML

      I understand that much, i just am not sure how to write the code to randomly select the numbers, and place them in the select boxes on the table and not duplicate the numbers if and when it could happen. I will also need a button to start the random number selection.

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Well, if this is to be a web-page, PHP would probably be easiest to get started with. C++ is more of a desktop language, and Java is kind of... heavy.

        Take a look at PHP's mt_rand function, and familiarize yourself with the while loop. If you don't want to get duplicate numbers from the random number generator (which kind of makes it... not random), then you will have to use a loop to select a new number over and over until you have a number that has not been selected before.

        Comment

        • jhernandy
          New Member
          • Sep 2010
          • 3

          #5
          Still need help

          loop would probably work best, what I might end up doing is using numbers 1-5 and and the numbers will randomly be assigned with no duplicates. I guess random is used loosely, since I don't want the numbers to be duplicated. Any other ideas will be appreciated.

          Comment

          Working...