Code Comments
Programming Forum and web based access to our favorite programming groups.Alright, I have one more task I am trying to solve today. That is to have a
random picture show up on my website. To make it easy (or so I believe) I
made both pictures the same size. One is called 1.jpg and other is 2.jpg.
Here is the basic idea I have to do so.
<?php
mt_rand(time());
$tmp = mt_rand(1,2);
if ($tmp == 1)
{
show one picture
}
else
{
show second picture
}
?>
Now the problem is, the "show one picture" and "show two picture". The line
of html coding I thus far is:
<img src="images/1.jpg" alt="Our store" width="210" height="250"
align="right">
So, how would I have the "images/1.jpg" reflect the $tmp ??? Thank you very
much in advance.
Lee
Post Follow-up to this messageOn 2004-03-21, Lee A. Wentzel wrote:
> Alright, I have one more task I am trying to solve today. That is to have
a
> random picture show up on my website. To make it easy (or so I believe) I
> made both pictures the same size. One is called 1.jpg and other is 2.jpg.
>
> Here is the basic idea I have to do so.
>
><?php
> mt_rand(time());
> $tmp = mt_rand(1,2);
> if ($tmp == 1)
> {
> show one picture
> }
> else
> {
> show second picture
> }
> ?>
>
> Now the problem is, the "show one picture" and "show two picture". The li
ne
> of html coding I thus far is:
>
><img src="images/1.jpg" alt="Our store" width="210" height="250"
> align="right">
>
> So, how would I have the "images/1.jpg" reflect the $tmp ??? Thank you ve
ry
> much in advance.
>
> Lee
>
How about :
<?php
mt_rand(time());
$tmp = mt_rand(1,2);
echo '<img src="images/'. $tmp .'.jpg" alt="Our store" width="210" height="2
50"
align="right">';
?>
--
Mike Peters
mike [-AT-] ice2o [-DOT-] com
http://www.ice2o.com
Post Follow-up to this messageMike Peters wrote: > On 2004-03-21, Lee A. Wentzel wrote: [...] > > How about : > <?php > mt_rand(time()); > $tmp = mt_rand(1,2); > echo '<img src="images/'. $tmp .'.jpg" alt="Our store" width="210" height ="250" > align="right">'; > ?> > How much better than rand() is mt_rand()? The manual says not to bother with the mersene twister but everyone else seems to recommend it.
Post Follow-up to this messageOn 2004-03-21, Patrick wrote: > Mike Peters wrote: > [...] > > How much better than rand() is mt_rand()? The manual says not to bother > with the mersene twister but everyone else seems to recommend it. rand() uses the libc rand() function which is considered fairly poor, as such, mt_rand() provides a much better algorithm which will result in a better spread and is much quicker. Also on Windows, RAND_MAX, when using rand(), is rather low at 32768, so if you expect to need larger values you should use mt_rand(). For examples such as the above however I doubt you'll see much difference between rand() and mt_rand(). -- Mike Peters mike [-AT-] ice2o [-DOT-] com http://www.ice2o.com
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.