Random Numbers PHP Script

Discussion in 'PHP' started by JamieH, May 5, 2008.

  1. #1
    Basically i found this small script on Google today, i just want to know a few answers:

    <?php 
    
    $random_number = rand(1,10);
    $random_numbertwo = rand(1,10); 
    
    print "<p>$random_number.</p>\n";
    print "<p>$random_numbertwo.</p>\n"; 
    
    ?>
    PHP:
    If i wanted to use this script at the backend of my website.. so when i press a button it will refresh the numbers and place the 2 numbers on the main page of the website so both numbers are seeable by the public. How would i do this?

    Is this safe? Can it be broken so people from the public can see what the next number will be?

    Is there a better way of doing it?

    Many thanks,
    Jamie Hann
     
    JamieH, May 5, 2008 IP
  2. ksamir2004

    ksamir2004 Peon

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try let me know update.. hope this will work fine
     
    ksamir2004, May 5, 2008 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    Yeah it is random..

    However, numbers from 1 to 10 are easy to guess, however, if you use 1 to 1000, it would be practically impossible to guess.

    Peace,
     
    Barti1987, May 5, 2008 IP
  4. JamieH

    JamieH Well-Known Member

    Messages:
    975
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    140
    Digital Goods:
    1
    Articles:
    1
    #4
    Thanks for the help guys.

    But what if i wanted to use this script in an admin panel.. so when i click on a button it will print the 2 random numbers on the homepage?

    Many thanks,
    Jamie Hann
     
    JamieH, May 5, 2008 IP
  5. Altari

    Altari Peon

    Messages:
    188
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Well, you could create a file that it would write to when you pressed the button, then include it wherever in your front page. Or you could add the numbers to the database and use them until you click the button again.
     
    Altari, May 5, 2008 IP
  6. SoftCloud

    SoftCloud Well-Known Member

    Messages:
    1,060
    Likes Received:
    28
    Best Answers:
    2
    Trophy Points:
    120
    #6
    The numbers will always be random so you cannot make them static.
     
    SoftCloud, May 5, 2008 IP
  7. Randombase

    Randombase Peon

    Messages:
    224
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Your md5 script is completely useless, it produces the same results but encrypted with a static algorithm, thus only producing ten results. The possible output would be:
    c4ca4238a0b923820dcc509a6f75849b (1)
    c81e728d9d4c2f636f067f89cc14862c  (2)
    ...
    d3d9446802a44259755d38e6d163e820 (10)
    Code (markup):
     
    Randombase, May 5, 2008 IP
  8. JamieH

    JamieH Well-Known Member

    Messages:
    975
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    140
    Digital Goods:
    1
    Articles:
    1
    #8
    If possible, i'd like the script to run exactly like this:

    Admin page

    *- The script sets the 2 numbers to 0 - 0 first before i press the button
    *- The random script.. with a button called "randomize"
    *- When i click the button, it will randomize the numbers, place the numbers into a mysql database, and then when i called the table and table info it will place the 2 numbers onto the main page.

    Main Page

    *- Two big boxes, with the 2 numbers in place, obviously being set to 0 - 0 before i push the button, then changing into the numbers that are now randomized.

    Can anyone give me a bit of code for each section if not give me tutorials so then i would know how to do this myself?

    Many thanks,
    Jamie Hann
     
    JamieH, May 5, 2008 IP
  9. ksamir2004

    ksamir2004 Peon

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thanks
    Sam
     
    ksamir2004, May 5, 2008 IP