View Full Version : Randomizer
kusadasi-guy
May 4th 2004, 5:52 am
i am creating random numbers with .ASP
<%
dim my_random
randomize
my_random = (Rnd*38)+1
%>
<img src="images/randım/picture-<%=int(my_random)%>.jpg">
That code snippet createing random numbers between 1-38.
How can i do that in PHP?
er2er
May 4th 2004, 8:49 am
<img src="images/randım/picture-<?=rand(1,39)?>.jpg">
Php automaticaly uses randomize, and rand() returns int.
kusadasi-guy
May 4th 2004, 9:08 am
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">
er2er
May 4th 2004, 9:53 am
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); ?>
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 :)
kusadasi-guy
May 4th 2004, 11:18 am
Thats Great! Thank you so much!!
Ohh God, what a beautiful language!
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.