Javascript Random equivalent in php

Discussion in 'PHP' started by Silver89, Oct 18, 2008.

  1. #1
    Hi,

    What's the equivalent to this javascript in php?

    Math.round(Math.random()*999999)
    Code (markup):
    Thanks
     
    Silver89, Oct 18, 2008 IP
  2. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #2
    mwasif, Oct 18, 2008 IP
  3. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #3
    Yeh I know how they both work in php, I'm just not sure if the rand() gives the same sort of Math.Random so the outcome number would be different in decimal places?
     
    Silver89, Oct 18, 2008 IP
  4. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #4
    rand() generates the integer.
     
    mwasif, Oct 18, 2008 IP
  5. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #5
    Yes, but I'm not sure if the outcome integer from the sequence would be the same length of digits in both occasions.
     
    Silver89, Oct 18, 2008 IP
  6. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #6
    Random means random. You cannot expect the same integer will be generated from both the scripts at the same time.
     
    mwasif, Oct 18, 2008 IP
  7. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #7
    I'm not, I just wanted the same digit integer, if I new how to do that in javascript then it would be simple, I know php you can use rand(1,100)
     
    Silver89, Oct 18, 2008 IP
  8. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Math.round(Math.random()*999999)

    would be

    rand(0,999999)

    this generates a random number between 0 and 999999
     
    Kyosys, Oct 19, 2008 IP