1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Randomizer

Discussion in 'C#' started by kusadasi-guy, May 4, 2004.

  1. #1
    i am creating random numbers with .ASP
    That code snippet createing random numbers between 1-38.
    SEMrush
    How can i do that in PHP?
     
    kusadasi-guy, May 4, 2004 IP
    SEMrush
  2. er2er

    er2er Peon

    Messages:
    9
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <img src="images/randım/picture-<?=rand(1,39)?>.jpg">
    Php automaticaly uses randomize, and rand() returns int.
     
    er2er, May 4, 2004 IP
    digitalpoint likes this.
  3. kusadasi-guy

    kusadasi-guy Peon

    Messages:
    83
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    OHHH!!!!! Thats GREAT!!!!!

    Thank you so much "er2er"

    How can i do this with a variable?


    <img src="images/randım/picture-<?=my_variable?>.jpg">
     
    kusadasi-guy, May 4, 2004 IP
  4. er2er

    er2er Peon

    Messages:
    9
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    In PHP variables starts with $, so
    <img src="images/randım/picture-<?=$my_variable?>.jpg">

    Some theory: ;-)
    <? is short php opening tag (equivalent og <?php) and ?> is a closing tag
    <?=... ?> is an equivalent of <? echo ... ?> (outputs ...)

    Now, you can use for example:
    <? $my_random = rand(1,39); ?>
    PHP:
    and then:
    <img src="images/random/picture-<?=$my_variable?>.jpg">

    If you want to use more advanced pseudo-random number generator, you can try mt_randomize() and mt_rand(1,39) - just to play with php :)
     
    er2er, May 4, 2004 IP
  5. kusadasi-guy

    kusadasi-guy Peon

    Messages:
    83
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thats Great! Thank you so much!!

    Ohh God, what a beautiful language!
     
    kusadasi-guy, May 4, 2004 IP