vary a number

Discussion in 'PHP' started by Catchpa, Jun 23, 2010.

  1. #1
    I can't arrive to let a value go up and down. If anyone can help me?

    Like this:

    'Alpa' have to circulate between 100 and 1000, the system chose the fall and the rise,
    lika the tradingmarket.

    'Beta' have to circulate between 10 and 70 for example, this numbers may change.

    etc...

    I hope someone can help me with the code to let numbers fall and rise...

    thanks a lot
     
    Catchpa, Jun 23, 2010 IP
  2. Michellu

    Michellu Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $alpa=$alpa+(rand(0,1)?-1:1)*rand(100, 1000);

    Explanation:

    rand(0,1) returns 0 or 1
    (rand(0,1)?-1:1) if it 0 is returned set the sign to minus (-) , if 1 is return set the sign to plus (+)
    rand(100, 1000) returns a value between 100 and 1000
     
    Michellu, Jun 23, 2010 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    Are you looking for a random number between those 2 points, or is there some logic that will determine the number?
     
    jestep, Jun 23, 2010 IP
  4. Catchpa

    Catchpa Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    look it's not on monday 700 and on wednesday only 100 left. It's have to different on a maximum of 20% a day...
     
    Catchpa, Jun 23, 2010 IP
  5. Michellu

    Michellu Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    something like this maybe:
    $alpa=$alpa+(rand(0,1)?-1:1)*rand(0, $alpa*0.20);

    you should explain your problem again...
     
    Michellu, Jun 23, 2010 IP
  6. Catchpa

    Catchpa Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I can't arrive to let alpa rise or fall. alpa have to rise or fall with maximum 20%.

    For example; monday it's 100, teusday 110, wednesday 105, thursday 120, friday 122, saturday 103, ........
     
    Catchpa, Jun 23, 2010 IP
  7. Michellu

    Michellu Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    My second example does exactly that, try it.
     
    Michellu, Jun 23, 2010 IP
  8. Catchpa

    Catchpa Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    woow great, I'll try, thanks a lot
     
    Catchpa, Jun 23, 2010 IP
  9. Michellu

    Michellu Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    you're welcome.
     
    Michellu, Jun 23, 2010 IP