Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

random picture
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



Report this thread to moderator Post Follow-up to this message
Old Post
Lee A. Wentzel
03-27-04 04:12 AM


Re: random picture
On 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

Report this thread to moderator Post Follow-up to this message
Old Post
Mike Peters
03-27-04 04:12 AM


Re: random picture
Mike 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.

Report this thread to moderator Post Follow-up to this message
Old Post
Patrick
03-27-04 04:12 AM


Re: random picture
On 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

Report this thread to moderator Post Follow-up to this message
Old Post
Mike Peters
03-27-04 04:12 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Language archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 03:44 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.