[PHP] Re: Random Flash Movies

2009-09-21 Thread Gary
As always, thanks for your help.

Gary


""Gary""  wrote in message 
news:68.43.09009.cba46...@pb1.pair.com...
>A question was posted on another board that the poster wanted random flash 
>movies to display as the page is reloaded.  I posted the script below and 
>said I thought it could be adapted but that the echo would probably need to 
>change. Can someone offer some guidance on this?  Thanks
>
> Gary
>
>  //Chooses a random number
> $num = Rand (1,6);
> //Based on the random number, gives a quote
> switch ($num)
> {
> case 1:
> echo "";
> break;
> case 2:
> echo "";
> break;
> case 3:
> echo "";
> break;
> case 4:
> echo "";
> break;
> case 5:
> echo "";
> break;
> case 6:
> echo "";
> }
> ?>
>
>
> __ Information from ESET Smart Security, version of virus 
> signature database 4441 (20090919) __
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
>
>
>
> __ Information from ESET Smart Security, version of virus 
> signature database 4442 (20090921) __
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
> 



__ Information from ESET Smart Security, version of virus signature 
database 4442 (20090921) __

The message was checked by ESET Smart Security.

http://www.eset.com





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Random Unique ID

2007-03-23 Thread Richard Lynch
On Wed, March 21, 2007 5:40 pm, [EMAIL PROTECTED] wrote:
> Thanks.  Yes, I check for errors.  But there are other types of errors
> so I'd need to verify that it is a duplicate key error and, in my
> ignorance, I have not yet figured out how to do that programatically.
> I worry about getting into an infinite loop.

Untested code:

//create table test_id (id char(32) unique not null primary key));

$success = 0;
while (!$success){
  $id = md5(uniqid());
  $query = "insert into test_id (id) values('$id')";
  $result = mysql_query($query);
  if (!$result){
//I don't promise 1023 is right.
//force a duplicate as a test to confirm
if (mysql_errno() == 1023){
  //duplicate key
  //we'll loop back and try with another
}
else{
  echo "Something went wrong with our database. Sorry.";
  error_log(mysql_error());
  break;
}
  }
  else{
$success = 1;
  }
}

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Random Unique ID

2007-03-23 Thread Satyam
I'm sorry if I am repeating something that has been said, but in the 
comments to:


http://es2.php.net/manual/en/function.uniqid.php

there is a little piece of code that generates UUID as per RFC 4122, and 
those get as unique as they come.  MySql has a UUID() function and so do any 
database engine that supports replication, since that's the only way to 
ensure keys won't get repeated over multiple servers.


Satyam




- Original Message - 
From: <[EMAIL PROTECTED]>

To: 
Sent: Friday, March 23, 2007 7:48 PM
Subject: [PHP] Re: Random Unique ID



Robert Cummings writes:

Bleh, you can solve this with at most 2 queries.


Thanks.  That is a bit different than what I was thinking
about but it might work for my purposes.  Thanks also to all
the other people who made suggestions.
It appears to me that ther are 3 distinct approaches.
1)  Generate a random number.  Query the DB to see if it has been
used before and if so generate another random number and repeat.  It
seems to me that this would require that the DB be locked for the
checking and insertion to make sure a duplicate was not slipped in.
2)  Generate a random number.  Make a trial insertion for a unique
field.  If the insertion fails repeat.  This functions just like the
above but uses Mysql's native behavior to handle the checking so no
user locking is necessary.  Almost all the time this will require
only 1 insertion whereas the above will require 2 or more accesses.
3)  Generate a unique identifier from the record sequence number.  Since
the sequence number is guaranteed to be unique the identifier will also
be unique and can be used without any worry.  There are various schemes
I can think of by which the unique identifier, altho uniquely determined
by the sequence number, can be generated so that it will not reveal the
sequence number and appear unpredictable.  This will require 3 accesses
to the DB (insertion, mysql_insert_id, and update).
I have a number of options to try and think about.  Thanks again.
Best,
Craig
--
- Virtual Phonecards - Instant Pin by Email  -
-   Large Selection - Great Rates-
- http://speedypin.com/?aff=743&co_branded=1 -
-- 



**
**
*  Craig Spencer *
*  [EMAIL PROTECTED]*
**
**
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.17/730 - Release Date: 
22/03/2007 7:44





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Random Unique ID

2007-03-23 Thread ccspencer
Robert Cummings writes: 


Bleh, you can solve this with at most 2 queries.


Thanks.  That is a bit different than what I was thinking
about but it might work for my purposes.  Thanks also to all
the other people who made suggestions. 


It appears to me that ther are 3 distinct approaches.
1)  Generate a random number.  Query the DB to see if it has been
used before and if so generate another random number and repeat.  It
seems to me that this would require that the DB be locked for the
checking and insertion to make sure a duplicate was not slipped in.
2)  Generate a random number.  Make a trial insertion for a unique
field.  If the insertion fails repeat.  This functions just like the
above but uses Mysql's native behavior to handle the checking so no
user locking is necessary.  Almost all the time this will require
only 1 insertion whereas the above will require 2 or more accesses.
3)  Generate a unique identifier from the record sequence number.  Since
the sequence number is guaranteed to be unique the identifier will also
be unique and can be used without any worry.  There are various schemes
I can think of by which the unique identifier, altho uniquely determined
by the sequence number, can be generated so that it will not reveal the
sequence number and appear unpredictable.  This will require 3 accesses
to the DB (insertion, mysql_insert_id, and update). 

I have a number of options to try and think about.  Thanks again. 

Best, 

Craig 


--
- Virtual Phonecards - Instant Pin by Email  -
-   Large Selection - Great Rates-
- http://speedypin.com/?aff=743&co_branded=1 -
-- 



**
**
*  Craig Spencer *
*  [EMAIL PROTECTED]*
**
** 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Random Unique ID

2007-03-22 Thread Mark
[EMAIL PROTECTED] wrote:

> Hello,
> 
> I want to add a random unique ID to a Mysql table.  Collisions
> are unlikely but possible so to handle those cases I'd like to
> regenerate the random ID until there is no collision and only
> then add my row.  Any suggestions for a newbie as to the right
> way to go about doing this?
> 
> Best,
> 
> Craig
> 
I just wrote up a quick PHP extension that will do what you want. It is on
my website, it is called muniqid, you can get it from the download area.
You can build it as part of PHP or used phpize, configure, make, make
install and create a module.

get it at http://ww.mohawksoft.org

It provides two functions:

muniqid_time(), and muniqid_rand().

muniqid_time() creates a GUID looking string that incorporates, time in
seconds, timer ticks, pid, ip address, and system stats to create an almost
certainly unique key with enough random data to make it impossible to
guess.

A duplicate is only possible within your web site (I guess it could happen
somewhere in the world), if you are using SMP motherboards and both
processors are processing a create ID, at *exactly* the same time (within
resolution of clock ticks) and are running in two threads within the same
process and rand() is isolated between threads and both threads have
processed the same number of IDs. Short of that, pretty impossible.

muniqid_rand() creates a GUID looking string that incorporates a lot of
random data from your machine. It may be less unique than muniqid_time, but
is far more random.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Random Unique ID

2007-03-22 Thread Mark
Tijnema ! wrote:

> On 3/22/07, markw@mohawksoft.com  wrote:
>> > On 3/22/07, Roman Neuhauser <[EMAIL PROTECTED]> wrote:
>> >> # markw@mohawksoft.com / 2007-03-22 08:49:59 -0400:
>> >> > Tijnema ! wrote:
>> >> >
>> >> > > On 3/22/07, Roman Neuhauser <[EMAIL PROTECTED]> wrote:
>> >> > >>
>> >> > >> http://www.ossp.org/pkg/lib/uuid
>> >> > >
>> >> > > Note that this doesn't gonna work when safe mode is on..!
>> >>
>> >> Ralf S. Engelschall's OSSP UUID library wrapped in a PHP extension
>> >> (shipped with the library) won't work in safe mode? How's that?
>> >
>> > I quote the wrong guy i think, i meant to quote this
>> >> If you are running Linux, you can get this using:
>> >>$GUID =  exec("uuidgen");
>> > As this is using the exec function, which doesn't work with safe mode
>> > on.
>> >
>> >
>> >>
>> >> > Generating a psudo-random unique key doesn't seem to be something
>> >> > PHP
>> >> does
>> >> > well. I can post an extension this afternoon if anyone wants to use
>> >> it.
>> >>
>> >> I'm curious.
>> >>
>>
>> Take a hop over to www.mohawksoft.org, and check out "download," download
>> MUniqID and tell me what you think.
>>
>> It should build as a module.
>>
>>
> I'm not sure where you want to use it for, but keep in mind that if
> you are gonna use external modules/applications it will probably work
> only on your development server. Not everyone (nearly nobody) has such
> modules installed, so if you are planning to distribute, you need to
> keep in mind that everyone that want's to use the script, will need to
> install the used module/app.


Well, it can build as part of PHP if you do a buildconf as well

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Random Unique ID

2007-03-22 Thread Tijnema !

On 3/22/07, markw@mohawksoft.com  wrote:

> On 3/22/07, Roman Neuhauser <[EMAIL PROTECTED]> wrote:
>> # markw@mohawksoft.com / 2007-03-22 08:49:59 -0400:
>> > Tijnema ! wrote:
>> >
>> > > On 3/22/07, Roman Neuhauser <[EMAIL PROTECTED]> wrote:
>> > >>
>> > >> http://www.ossp.org/pkg/lib/uuid
>> > >
>> > > Note that this doesn't gonna work when safe mode is on..!
>>
>> Ralf S. Engelschall's OSSP UUID library wrapped in a PHP extension
>> (shipped with the library) won't work in safe mode? How's that?
>
> I quote the wrong guy i think, i meant to quote this
>> If you are running Linux, you can get this using:
>>$GUID =  exec("uuidgen");
> As this is using the exec function, which doesn't work with safe mode on.
>
>
>>
>> > Generating a psudo-random unique key doesn't seem to be something PHP
>> does
>> > well. I can post an extension this afternoon if anyone wants to use
>> it.
>>
>> I'm curious.
>>

Take a hop over to www.mohawksoft.org, and check out "download," download
MUniqID and tell me what you think.

It should build as a module.



I'm not sure where you want to use it for, but keep in mind that if
you are gonna use external modules/applications it will probably work
only on your development server. Not everyone (nearly nobody) has such
modules installed, so if you are planning to distribute, you need to
keep in mind that everyone that want's to use the script, will need to
install the used module/app.

Tijnema





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Random Unique ID

2007-03-22 Thread markw
> On 3/22/07, Roman Neuhauser <[EMAIL PROTECTED]> wrote:
>> # markw@mohawksoft.com / 2007-03-22 08:49:59 -0400:
>> > Tijnema ! wrote:
>> >
>> > > On 3/22/07, Roman Neuhauser <[EMAIL PROTECTED]> wrote:
>> > >>
>> > >> http://www.ossp.org/pkg/lib/uuid
>> > >
>> > > Note that this doesn't gonna work when safe mode is on..!
>>
>> Ralf S. Engelschall's OSSP UUID library wrapped in a PHP extension
>> (shipped with the library) won't work in safe mode? How's that?
>
> I quote the wrong guy i think, i meant to quote this
>> If you are running Linux, you can get this using:
>>$GUID =  exec("uuidgen");
> As this is using the exec function, which doesn't work with safe mode on.
>
>
>>
>> > Generating a psudo-random unique key doesn't seem to be something PHP
>> does
>> > well. I can post an extension this afternoon if anyone wants to use
>> it.
>>
>> I'm curious.
>>

Take a hop over to www.mohawksoft.org, and check out "download," download
MUniqID and tell me what you think.

It should build as a module.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Random Unique ID

2007-03-22 Thread Tijnema !

On 3/22/07, Roman Neuhauser <[EMAIL PROTECTED]> wrote:

# markw@mohawksoft.com / 2007-03-22 08:49:59 -0400:
> Tijnema ! wrote:
>
> > On 3/22/07, Roman Neuhauser <[EMAIL PROTECTED]> wrote:
> >>
> >> http://www.ossp.org/pkg/lib/uuid
> >
> > Note that this doesn't gonna work when safe mode is on..!

Ralf S. Engelschall's OSSP UUID library wrapped in a PHP extension
(shipped with the library) won't work in safe mode? How's that?


I quote the wrong guy i think, i meant to quote this

If you are running Linux, you can get this using:
   $GUID =  exec("uuidgen");

As this is using the exec function, which doesn't work with safe mode on.




> Generating a psudo-random unique key doesn't seem to be something PHP does
> well. I can post an extension this afternoon if anyone wants to use it.

I'm curious.

--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Random Unique ID

2007-03-22 Thread Roman Neuhauser
# markw@mohawksoft.com / 2007-03-22 08:49:59 -0400:
> Tijnema ! wrote:
> 
> > On 3/22/07, Roman Neuhauser <[EMAIL PROTECTED]> wrote:
> >>
> >> http://www.ossp.org/pkg/lib/uuid
> > 
> > Note that this doesn't gonna work when safe mode is on..!
 
Ralf S. Engelschall's OSSP UUID library wrapped in a PHP extension
(shipped with the library) won't work in safe mode? How's that?

> Generating a psudo-random unique key doesn't seem to be something PHP does
> well. I can post an extension this afternoon if anyone wants to use it.

I'm curious.

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Random Unique ID

2007-03-22 Thread Mark
Tijnema ! wrote:

> On 3/22/07, Roman Neuhauser <[EMAIL PROTECTED]> wrote:
>> # [EMAIL PROTECTED] / 2007-03-21 21:03:35 -0500:
>> > Mark wrote:
>> > >[EMAIL PROTECTED] wrote:
>> > >
>> > >>Hello,
>> > >>
>> > >>I want to add a random unique ID to a Mysql table.  Collisions
>> > >>are unlikely but possible so to handle those cases I'd like to
>> > >>regenerate the random ID until there is no collision and only
>> > >>then add my row.  Any suggestions for a newbie as to the right
>> > >>way to go about doing this?
>> > >>
>> > >>Best,
>> > >>
>> > >>Craig
>> > >.
>> > >
>> > >I suggest looking into a GUID sort of thing, it is all coded for you
>> > >and it works just like you want.
>> >
>> > If you are running Linux, you can get this using:
>> >$GUID =  exec("uuidgen");
>>
>> http://www.ossp.org/pkg/lib/uuid
> 
> Note that this doesn't gonna work when safe mode is on..!

Generating a psudo-random unique key doesn't seem to be something PHP does
well. I can post an extension this afternoon if anyone wants to use it.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Random Unique ID

2007-03-22 Thread Tijnema !

On 3/22/07, Roman Neuhauser <[EMAIL PROTECTED]> wrote:

# [EMAIL PROTECTED] / 2007-03-21 21:03:35 -0500:
> Mark wrote:
> >[EMAIL PROTECTED] wrote:
> >
> >>Hello,
> >>
> >>I want to add a random unique ID to a Mysql table.  Collisions
> >>are unlikely but possible so to handle those cases I'd like to
> >>regenerate the random ID until there is no collision and only
> >>then add my row.  Any suggestions for a newbie as to the right
> >>way to go about doing this?
> >>
> >>Best,
> >>
> >>Craig
> >.
> >
> >I suggest looking into a GUID sort of thing, it is all coded for you and it
> >works just like you want.
>
> If you are running Linux, you can get this using:
>$GUID =  exec("uuidgen");

http://www.ossp.org/pkg/lib/uuid


Note that this doesn't gonna work when safe mode is on..!


--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Random Unique ID

2007-03-22 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2007-03-21 21:03:35 -0500:
> Mark wrote:
> >[EMAIL PROTECTED] wrote:
> >
> >>Hello,
> >>
> >>I want to add a random unique ID to a Mysql table.  Collisions
> >>are unlikely but possible so to handle those cases I'd like to
> >>regenerate the random ID until there is no collision and only
> >>then add my row.  Any suggestions for a newbie as to the right
> >>way to go about doing this?
> >>
> >>Best,
> >>
> >>Craig
> >.
> >
> >I suggest looking into a GUID sort of thing, it is all coded for you and it
> >works just like you want.
> 
> If you are running Linux, you can get this using:
>$GUID =  exec("uuidgen");

http://www.ossp.org/pkg/lib/uuid

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Random Unique ID

2007-03-21 Thread Robert Cummings
On Thu, 2007-03-22 at 08:14 +0400, Rabih Tayyem wrote:
> Actually I told you that the possibility of collision is small because I
> wanted to be scientific
> Scientifically, I can say this posibilty goes to 0...

Only as the length of the ID approaches infinity :B

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Random Unique ID

2007-03-21 Thread Rabih Tayyem

Actually I told you that the possibility of collision is small because I
wanted to be scientific
Scientifically, I can say this posibilty goes to 0...
It is a random ID (not a totally random but based on the current timestamp)
generated not only once but twice based on two different time stamps.

Safe enough I believe...

Regards,
Rabih G. Tayyem

On 3/22/07, Jim Moseby <[EMAIL PROTECTED]> wrote:


> Rabih Tayyem writes:
>
> > PS: I don't take credit for the code as it is a modified version of
> > a code I found long time back (this same code is running on one of
> > my applications for months without any problem)..
>
> Thanks.  I'll find use for that!
>
> However, altho I know that by making the random number big enough
> the likelyhood of collisions can be made vanishingly small, I was
> actually concerned with eliminating the possibility of collisions
> altogether by checking to see if the number had been used before.
>
> I just don't know how to do that properly with Mysql.  Perhaps it
> is necessary to lock to table, check, make the insert and then
> unlock it.  But I was hoping that there would be a simpler way.

Replied off-list with a solution.

JM

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Random Unique ID

2007-03-21 Thread Myron Turner

Mark wrote:

[EMAIL PROTECTED] wrote:


Hello,

I want to add a random unique ID to a Mysql table.  Collisions
are unlikely but possible so to handle those cases I'd like to
regenerate the random ID until there is no collision and only
then add my row.  Any suggestions for a newbie as to the right
way to go about doing this?

Best,

Craig

.

I suggest looking into a GUID sort of thing, it is all coded for you and it
works just like you want.


If you are running Linux, you can get this using:
   $GUID =  exec("uuidgen");
--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Random Unique ID

2007-03-21 Thread Mark
[EMAIL PROTECTED] wrote:

> Hello,
> 
> I want to add a random unique ID to a Mysql table.  Collisions
> are unlikely but possible so to handle those cases I'd like to
> regenerate the random ID until there is no collision and only
> then add my row.  Any suggestions for a newbie as to the right
> way to go about doing this?
> 
> Best,
> 
> Craig

First some computer science 101: A random number is not unique and a unique
number is not random. Learn it, know it, live it.

What you need is a component of the ID which is not random, but is probably
unique within the environment. Say, the IP address of the machine. Then,
perhaps the process id of Apache/PHP process. Then, the random component,
the time() (which is random with respect to the request, but unique for one
second), followed by some rand() requests seeded by some high resolution
micro timer. This will have a HUGH probability of uniqueness within the
single process, so it is virtually assured, and a guarantee of uniqueness
across all other processes and machines.

I suggest looking into a GUID sort of thing, it is all coded for you and it
works just like you want.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Random Unique ID

2007-03-21 Thread Robert Cummings
On Wed, 2007-03-21 at 16:40 -0600, [EMAIL PROTECTED] wrote:
> Jim Moseby writes: 
> 
> >> However, altho I know that by making the random number big enough
> >> the likelyhood of collisions can be made vanishingly small, I was
> >> actually concerned with eliminating the possibility of collisions
> >> altogether by checking to see if the number had been used before.  
> >> 
> >> I just don't know how to do that properly with Mysql.  Perhaps it
> >> is necessary to lock to table, check, make the insert and then
> >> unlock it.  But I was hoping that there would be a simpler way. 
> > 
> > One way is to make your id field a unique key.  MySQL will not let 
> > you insert a record with a duplicate unique key, and will issue an 
> > error.  Your code should always check for errors on insert anyway, 
> > so if you get an error, generate a new key and try again.
> 
> Thanks.  Yes, I check for errors.  But there are other types of errors
> so I'd need to verify that it is a duplicate key error and, in my
> ignorance, I have not yet figured out how to do that programatically.
> I worry about getting into an infinite loop.

Bleh, you can solve this with at most 2 queries.


CREATE TABLE foo
(
id  INT   NOT NULL AUTO_INCREMENT,
uid char( 50 ),

PRIMARY KEY ( id )
);  




There you go, a 50 character highly unguessable and guaranteed unique
ID. Sure everyone knows the ID of the entry now, but that shouldn't be
important. In fact it optimizes retrieval and validation by allowing the
lookup to occur on an integer then validation by matching the full UID
against the UID found for the ID. In all honesty though, hitting the
database with random generated md5() hashes is probably more efficient
since the likelihood of a collision is small and so in most cases you
will only make one database query.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Random Unique ID

2007-03-21 Thread ccspencer
Jim Moseby writes: 


However, altho I know that by making the random number big enough
the likelyhood of collisions can be made vanishingly small, I was
actually concerned with eliminating the possibility of collisions
altogether by checking to see if the number had been used before.  


I just don't know how to do that properly with Mysql.  Perhaps it
is necessary to lock to table, check, make the insert and then
unlock it.  But I was hoping that there would be a simpler way. 


One way is to make your id field a unique key.  MySQL will not let 
you insert a record with a duplicate unique key, and will issue an 
error.  Your code should always check for errors on insert anyway, 
so if you get an error, generate a new key and try again.


Thanks.  Yes, I check for errors.  But there are other types of errors
so I'd need to verify that it is a duplicate key error and, in my
ignorance, I have not yet figured out how to do that programatically.
I worry about getting into an infinite loop. 

Best, 

Craig 




--
- Virtual Phonecards - Instant Pin by Email  -
-   Large Selection - Great Rates-
- http://speedypin.com/?aff=743&co_branded=1 -
-- 



**
**
*  Craig Spencer *
*  [EMAIL PROTECTED]*
**
** 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Random Unique ID

2007-03-21 Thread Stut

[EMAIL PROTECTED] wrote:

Stut writes:

[EMAIL PROTECTED] wrote:

I want to add a random unique ID to a Mysql table.  Collisions
are unlikely but possible so to handle those cases I'd like to
regenerate the random ID until there is no collision and only
then add my row.  Any suggestions for a newbie as to the right
way to go about doing this?


1) Not even slightly PHP related.


Perhaps not.  It is Mysql related.  And seeing other Mysql discussion
on this list inspired me to ask.


I refer you to the comment made earlier today by one of my honourable 
colleagues regarding murder.



2) Why random? Incrementing not good enough for you?


I want to use it in a way that will expose it to the user.  And I
don't want to give out information as to the order of records in
my database.


This is not security. Your site should prevent them from accessing data 
they should not be accessing. If you're worried that they can do this 
simply by changing a number in a query string then you really need to 
rethink the way the site works.


If you decide to ignore my advice, then the only way to do this is to 
set the ID field as unique, pick a random number and try to insert the 
row. Repeat until the insert succeeds. Yes it sucks, but so does what 
you are trying to do.


-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Re: Random Unique ID

2007-03-21 Thread Jim Moseby
> Rabih Tayyem writes: 
> 
> > PS: I don't take credit for the code as it is a modified version of 
> > a code I found long time back (this same code is running on one of 
> > my applications for months without any problem)..
> 
> Thanks.  I'll find use for that! 
> 
> However, altho I know that by making the random number big enough
> the likelyhood of collisions can be made vanishingly small, I was
> actually concerned with eliminating the possibility of collisions
> altogether by checking to see if the number had been used before. 
> 
> I just don't know how to do that properly with Mysql.  Perhaps it
> is necessary to lock to table, check, make the insert and then
> unlock it.  But I was hoping that there would be a simpler way. 

Replied off-list with a solution.

JM

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Random Unique ID

2007-03-21 Thread ccspencer
Rabih Tayyem writes: 

PS: I don't take credit for the code as it is a modified version of 
a code I found long time back (this same code is running on one of 
my applications for months without any problem)..


Thanks.  I'll find use for that! 


However, altho I know that by making the random number big enough
the likelyhood of collisions can be made vanishingly small, I was
actually concerned with eliminating the possibility of collisions
altogether by checking to see if the number had been used before. 


I just don't know how to do that properly with Mysql.  Perhaps it
is necessary to lock to table, check, make the insert and then
unlock it.  But I was hoping that there would be a simpler way. 

Best, 

Craig 




On 3/21/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:


Hello, 


I want to add a random unique ID to a Mysql table.  Collisions
are unlikely but possible so to handle those cases I'd like to
regenerate the random ID until there is no collision and only
then add my row.  Any suggestions for a newbie as to the right
way to go about doing this? 

Best, 

Craig 


--
- Virtual Phonecards - Instant Pin by Email  -
-   Large Selection - Great Rates-
- http://speedypin.com/?aff=743&co_branded=1 -
-- 



**
**
*  Craig Spencer *
*  [EMAIL PROTECTED]*
**
** 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php 







--
- Virtual Phonecards - Instant Pin by Email  -
-   Large Selection - Great Rates-
- http://speedypin.com/?aff=743&co_branded=1 -
-- 



**
**
*  Craig Spencer *
*  [EMAIL PROTECTED]*
**
** 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Random Unique ID

2007-03-21 Thread ccspencer
Stut writes: 


[EMAIL PROTECTED] wrote:

I want to add a random unique ID to a Mysql table.  Collisions
are unlikely but possible so to handle those cases I'd like to
regenerate the random ID until there is no collision and only
then add my row.  Any suggestions for a newbie as to the right
way to go about doing this?


1) Not even slightly PHP related.


Perhaps not.  It is Mysql related.  And seeing other Mysql discussion
on this list inspired me to ask. 


2) Why random? Incrementing not good enough for you?


I want to use it in a way that will expose it to the user.  And I
don't want to give out information as to the order of records in
my database. 

Best, 

Craig 



--
- Virtual Phonecards - Instant Pin by Email  -
-   Large Selection - Great Rates-
- http://speedypin.com/?aff=743&co_branded=1 -
-- 



**
**
*  Craig Spencer *
*  [EMAIL PROTECTED]*
**
** 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Random Record Retrieval

2004-05-23 Thread Martin Geisler
[EMAIL PROTECTED] (Robb Kerr) writes:

> How's that for alliteration in a subject line?

Very nice! :-)

> [...]  And, if this is the best way to go, unfortunately I don't
> know how to write a random number generator in PHP so would
> appreciate any help.

Your idea sounds good, and luckily you don't have to build your own
random generator, behold:

  http://php.net/rand

Then call rand() with two arguments: the minimum and maximum ID, and
it will give you a random integer back between those two numbers.

You could also opt to have MySQL make the random number for you, and
then do a query like

  SELECT * FROM table ORDER BY RAND() LIMIT 1;

Then you wont have to deal with figuring out the number of rows in the
table as you would in the PHP case.  You can also increse the limit
to, say, 3 and then show three random quotes on your pages.  See

  http://dev.mysql.com/doc/mysql/en/Mathematical_functions.html#IDX1363

for a description of RAND() in MySQL.

-- 
Martin Geisler  My GnuPG Key: 0xF7F6B57B

PHP EXIF Library  |  PhpWeather  |  PhpShell
http://pel.sf.net/|  http://phpweather.net/  |  http://gimpster.com/
Read/write EXIF data  |  Show current weather|  A shell in a browser

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: random?

2004-01-29 Thread Rob Adams
"Chris" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> $sql = "SELECT * FROM agentdb WHERE ((OfficeID <> 214) and
> (agentdb.agent_id<> 1115421) and (agentdb.agent_id > 100) and
> agentdb.agent_id <> 333)) ORDER BY RAND() LIMIT 1";
>
> The above code should generate a random agent upon refresh.
>
> It does however seem to favor one agent more than the others. The agent id
>
> it used to favor was "333" i added the "(agentdb.agent_id <> 333)" to
>
> disallow that agent from being displayed. But now it wants to favor an
agent
>
> whose id number is "1167553"
>
> The function can be seen here: http://c21alliancerealty.com/area.php it is
>
> the random "Featured Agent" on the left hand side of the page.
>
> Does anyone have any suggestions as to why this is occuring, please?

I don't have any suggestions as to why this happens.  Very strange.  One
thing you could do instead is depend on PHP's random numbers.

srand ((double) microtime() * 100);
$r = mysql_query('select count(*) as cnt from agentb');
$cnt = mysql_result($r, 0, 0);
mysql_free_result($r);
$rnd = rand(1, $cnt);
$sql = "SELECT * FROM agentdb WHERE ((OfficeID <> 214) and
(agentdb.agent_id<> 1115421) and (agentdb.agent_id > 100) and
agentdb.agent_id <> 333)) LIMIT $rnd, 1";

A bit more work than just relying on MySQL, but maybe it will actually be
random...

  -- Rob

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Random Numbers..

2003-12-08 Thread Curt Zirzow
* Thus wrote Burrito Warrior ([EMAIL PROTECTED]):
> 
> This would:
> /* selecting a random record, where n = 1.  Works fine on small tables */
> mysql> SELECT value FROM table ORDER BY RAND() LIMIT n;
> 
> /* selecting a random record.  This is good on large tables if numbering
> sequence is used */
> mysql> SET @val = FLOOR(RAND() * n) + 1;
> mysql> SELECT value FROM table WHERE ID = @val;

If two queries is acceptable: select a count() on a unique/primary
key, it should minimal overhead since the value is obtained very
quickly with those columns. then do a limit...

SELECT FLOOR(RAND() * COUNT(id)) + 1 as n FROM table;
SELECT value FROM table LIMIT n, 1

return 1 record starting to the nth record. There still lies the
performance loss the larger n becomes.


Or using the ID method:

SELECT FLOOR(RAND() * MAX(id)) + 1 as n FROM table;
SELECT value FROM table id >= n LIMIT 1

This might be the optimal in the two query method. Since it will
use the index to seek id >= n.


Curt
-- 
If eval() is the answer, you're almost certainly asking the
wrong question. -- Rasmus Lerdorf, BDFL of PHP

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Random Numbers..

2003-12-07 Thread Luke
select all and
use
mysql_data_seek($result, rand(mysql_num_rows($result) - 1));
$row = mysql_fetch_assoc($result);

and there, your random row is returnd, that should be easy enough :) and it
should work

-- 
Luke

"Theheadsage" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hey,
>
> I've got a script which used to generate a random quote. It worked fine
> untill this problem occurred..
>
> Say we have 4 quotes with QuoteID's of 1 through to 4
> The script would grab a number of rows, and generate a random number
> between 1 and this value (being 4 in this case) This worked fine untill,
> one of the quotes was removed and another added, leaving 4 quotes once
> again, but the last one had an ID of 5. The problem is the Random number
> generated is between 1 and 4, so the final quote is never shown..
>
> I tried using the RAND() function in the MySQL statement it's self, but
> it's not random enough...
>
> Then I thought of doing this:
>
> Select all the Quote ID's from the DB.
> Store them in an Array.
> Generate a random number between 1 and the last ID.
> If the Random Number matches a Quote ID, then display the quote,
> otherwise Generate another
>
> But I couldn't get the code to work. Any suggestions on either how to
> write the above, or made the MySQL RAND() function, more random?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Re: Random Numbers..

2003-12-06 Thread Burrito Warrior
No, I wouldn't do that.  What if another quote gets deleted.  The new
assigned
QuoteID would be 6 and your solution wouldn't work.

This would:
/* selecting a random record, where n = 1.  Works fine on small tables */
mysql> SELECT value FROM table ORDER BY RAND() LIMIT n;

/* selecting a random record.  This is good on large tables if numbering
sequence is used */
mysql> SET @val = FLOOR(RAND() * n) + 1;
mysql> SELECT value FROM table WHERE ID = @val;

-Original Message-
From: Alex [mailto:[EMAIL PROTECTED]
Sent: Sunday, December 07, 2003 12:00 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Re: Random Numbers..


Theheadsage wrote:
> Hey,
>
> I've got a script which used to generate a random quote. It worked fine
> untill this problem occurred..
>
> Say we have 4 quotes with QuoteID's of 1 through to 4
> The script would grab a number of rows, and generate a random number
> between 1 and this value (being 4 in this case) This worked fine untill,
> one of the quotes was removed and another added, leaving 4 quotes once
> again, but the last one had an ID of 5. The problem is the Random number
> generated is between 1 and 4, so the final quote is never shown..
>
> I tried using the RAND() function in the MySQL statement it's self, but
> it's not random enough...
>
> Then I thought of doing this:
>
> Select all the Quote ID's from the DB.
> Store them in an Array.
> Generate a random number between 1 and the last ID.
> If the Random Number matches a Quote ID, then display the quote,
> otherwise Generate another
>
> But I couldn't get the code to work. Any suggestions on either how to
> write the above, or made the MySQL RAND() function, more random?

how about if ($randnumber == 4) $randnumber++; ?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Random Numbers..

2003-12-06 Thread Alex
Theheadsage wrote:
Hey,

I've got a script which used to generate a random quote. It worked fine
untill this problem occurred..
Say we have 4 quotes with QuoteID's of 1 through to 4
The script would grab a number of rows, and generate a random number
between 1 and this value (being 4 in this case) This worked fine untill,
one of the quotes was removed and another added, leaving 4 quotes once
again, but the last one had an ID of 5. The problem is the Random number
generated is between 1 and 4, so the final quote is never shown..
I tried using the RAND() function in the MySQL statement it's self, but
it's not random enough...
Then I thought of doing this:

Select all the Quote ID's from the DB.
Store them in an Array.
Generate a random number between 1 and the last ID.
If the Random Number matches a Quote ID, then display the quote,
otherwise Generate another
But I couldn't get the code to work. Any suggestions on either how to
write the above, or made the MySQL RAND() function, more random?
how about if ($randnumber == 4) $randnumber++; ?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Random Quotes...

2003-10-22 Thread Kevin Stone

"Payne" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Hi,
> 
> I am working on a project and I need to see sample quote for doing 
> random quotes. These quotes will be put from a database. Can some please 
> share me some sample code. Thanks.
> 
> Chuck

For more solutions go to, http://groups.google.com
and type in, "select random row mysql"

- Kevin


[PHP] Re: Random Image Store

2003-06-11 Thread Hugh Bothwell
"Monil Chheda" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I want to create an php system that prevents automated
> registrations.
>
> I have come up with the script in which users come
> over and need to enter a random key displayed on the
> images while submitting their info. If the number
> entered is correct, the post is submitted, else, the
> same form is displayed with another random key.
>
> Now, any one doing a "View Source" gets to know the
> image source as "myscript.php". What I want to do is
> to save the .jpeg image on my disc with the name as
> "randomnumber.jpeg" , where randomnumber is generated
> randomly for that page.
>
> Then, I would put an  tag
> and no one will be able to get the name of my php file
> creating the image.


Why should it matter whether they know the generating
script's name?

The only important thing is that they can't easily read
off (or generate) the password-value passed to the
image-creation script.  You could store the passcode
as a session variable, or send it as an encrypted get-
variable, or hash into a stored dictionary.

--
Hugh Bothwell [EMAIL PROTECTED] Kingston ON Canada
v3.1 GCS/E/AT d- s+: a- C+++ L++>+++$ P+ E- W+++$ N++ K? w++ M PS+
PE++ Y+ PGP+ t-- 5++ !X R+ tv b DI+++ D-(++) G+ e(++) h-- r- y+




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Re: Random numbers in a cronned script?

2002-09-13 Thread Martin Towell

if you seed it with unix time then you'll alway be seeding with something
different
in most cases, the random numbers that are generated will be random enough

just my AU2c worth
Martin

-Original Message-
From: lallous [mailto:[EMAIL PROTECTED]]
Sent: Friday, September 13, 2002 6:51 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Re: Random numbers in a cronned script?


Yes, you're right about that point since the seed in most cases is computed
from system time => increasing probability of having same number @ the same
request time...
you can change the seed with the time() too (not all days are the same).

hope to hear others' opinions too.

Elias

"Leif K-Brooks" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I'm wondering if random numbers in a cronned script would be anywhere
> near random (I know that rand() isn't true random, but I don't want
> every number to be the same...)?  Since the number is seeded from
> time... and cron runs by time...
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Random numbers in a cronned script?

2002-09-13 Thread lallous

Yes, you're right about that point since the seed in most cases is computed
from system time => increasing probability of having same number @ the same
request time...
you can change the seed with the time() too (not all days are the same).

hope to hear others' opinions too.

Elias

"Leif K-Brooks" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I'm wondering if random numbers in a cronned script would be anywhere
> near random (I know that rand() isn't true random, but I don't want
> every number to be the same...)?  Since the number is seeded from
> time... and cron runs by time...
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Random Passwords Generator

2002-08-17 Thread Manuel Lemos

Hello,

On 08/18/2002 01:51 AM, César aracena wrote:
> Hi all. I know there must be several ways of doing this but I wonder
> what the best solution is. I'm tired of making and looking at scripts
> that creates random passwords for users from a "words.txt" list. These
> kind of passwords are limited only to the number of strange words your
> fingers type into a file, for which I think it's not the most secure way
> of giving away new passwords. I know there are other types of password
> generating scripts, but I want to know from the users of this list which
> would be the best one.
> 
> I think that pre-made passwords (choose randomly) are dangerous, because
> most users DO NOT change their given password once received and hackers
> CAN access that words.txt file no matter what level of protection you
> use for that server/folder.
> 
> Isn't there a function or something that would generate random passwords
> following given rules like:
> 
> - from x to y characters long.
> - lower AND/OR upper case.
> - numbers AND characters combination.
> - random numbers AND characters.
> 
> Which are the functions (or combination of functions) I can use to
> achieve this? Thanks in advance,

You may want to try some ready to use components for that same purpose 
like these:

http://www.phpclasses.org/passwordgenerator

http://www.phpclasses.org/securepwd



-- 

Regards,
Manuel Lemos


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Random mirrors and download quota

2002-08-11 Thread B.C. Lance

how about using the counter to store an id of the mirrors instead of 
randomly picking one? this will provide you a sequential traverse 
through all mirror sites.

if there are 10 sites, the counter will always be from 0 -> 9. this way 
each mirror site will have equal share on hits. so if the counter == 2, 
your script will know that the next hit will be to mirror site 2.

$_nextSite = (isset($_nextSite))?++$_nextSite % 10:0;

the above code will always ensure the counter counts from:
0 -> 9 -> 0 -> ...

this way, you can store all counters (into database?) on the main site 
for all mirrors.

> 
> "Andrew Conner" <[EMAIL PROTECTED]> escreveu na mensagem
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> 
>>Hello,
>>I have a script (at bottom) that, upon loading, will randomly select a
>>mirror or primary server (on average, the primary servers will be selected
>>twice as much). It all works good, but now, I have to add a "quota
> 
> manager"
> 
>>that will, for both mirrors, limit the times the file can be downloaded to
>>1200 times (there is only one file being downloaded). I have thought about
>>storing a text file for each of the two mirrors that shows the current
> 
> count
> 
>>of downloads, and it will be checked if the mirror is randomly selected
> 
> and
> 
>>if it is above 1200, will randomly select another server, and if it isn't,
>>will just add one to it and update the file. How would I go about this, or
>>is there a better way to do this?
>>Thanks in advance.
>>Andrew Conner
>>
>>The script (I know it doesn't use the best design, but it works, any
> 
> better
> 
>>ways of doing this?):
>>
>>>
>>// This array holds the servers, and has a double entry for the primary
>>servers
>>
>>$adArr = array("http://www.someprimaryserver.com/file.exe";,
>>
>>"http://www.someprimaryserver.com/file.exe";,
>>
>>"http://www.someprimaryserver2.com/file.exe";,
>>
>>"http://www.someprimaryserver2.com/file.exe";,
>>
>>"http://www.someprimaryserver3.com/file.exe";,
>>
>>"http://www.someprimaryserver3.com/file.exe";,
>>
>>"http://www.someprimaryserver4.com/file.exe";,
>>
>>"http://www.someprimaryserver4.com/file.exe";,
>>
>>"http://www.somemirror.com/file.exe";,
>>
>>"http://www.somemirror2.com/file.exe";);
>>
>>// This randomly gets a server...
>>
>>srand((double)microtime()*100);
>>
>>$wOne = rand(0, 9);
>>
>>$choice = $adArr[$wOne];
>>
>>// This fwds the user to the server picked.
>>
>>// Somewhere in here needs to be the mirror stuff...
>>
>>header("Location: $choice");
>>
>>?>
>>
>>
>>
> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Random mirrors and download quota

2002-08-11 Thread Julio Nobrega

Seems good to me, only this part:

> and it will be checked if the mirror is randomly selected and
> if it is above 1200, will randomly select another server

  It's better to select those under 1200 right from the start. If you have
10 servers, you might make 9 checks before selecting the last one.

--
Julio Nobrega
Pode acessar:
http://www.inerciasensorial.com.br


"Andrew Conner" <[EMAIL PROTECTED]> escreveu na mensagem
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hello,
> I have a script (at bottom) that, upon loading, will randomly select a
> mirror or primary server (on average, the primary servers will be selected
> twice as much). It all works good, but now, I have to add a "quota
manager"
> that will, for both mirrors, limit the times the file can be downloaded to
> 1200 times (there is only one file being downloaded). I have thought about
> storing a text file for each of the two mirrors that shows the current
count
> of downloads, and it will be checked if the mirror is randomly selected
and
> if it is above 1200, will randomly select another server, and if it isn't,
> will just add one to it and update the file. How would I go about this, or
> is there a better way to do this?
> Thanks in advance.
> Andrew Conner
>
> The script (I know it doesn't use the best design, but it works, any
better
> ways of doing this?):
> 
> 
> // This array holds the servers, and has a double entry for the primary
> servers
>
> $adArr = array("http://www.someprimaryserver.com/file.exe";,
>
> "http://www.someprimaryserver.com/file.exe";,
>
> "http://www.someprimaryserver2.com/file.exe";,
>
> "http://www.someprimaryserver2.com/file.exe";,
>
> "http://www.someprimaryserver3.com/file.exe";,
>
> "http://www.someprimaryserver3.com/file.exe";,
>
> "http://www.someprimaryserver4.com/file.exe";,
>
> "http://www.someprimaryserver4.com/file.exe";,
>
> "http://www.somemirror.com/file.exe";,
>
> "http://www.somemirror2.com/file.exe";);
>
> // This randomly gets a server...
>
> srand((double)microtime()*100);
>
> $wOne = rand(0, 9);
>
> $choice = $adArr[$wOne];
>
> // This fwds the user to the server picked.
>
> // Somewhere in here needs to be the mirror stuff...
>
> header("Location: $choice");
>
> ?>
>
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Random number Question

2002-04-29 Thread Dan Koken

OOPS!
You are right on..
I noticed my error after I sent it. The name='guess' was on the input.??
Daaa! it's Monday .. OK!!
This should work:
===


The computer has picked $another number between 1 and 10.
Guess the number and you win!

Enter your guess:


";

if (isset($guess))
{
srand((double)microtime()*100);
$number = floor(rand(1,10));

echo "The number is: $number";

if ($guess == $number)
echo 'You have won!';
  else  echo "Sorry that wasn't the answer";

}
?>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Random number Question

2002-04-29 Thread Dan Koken

Try something like this and see if it works???



The computer has picked $another number between 1 and 10.
Guess the number and you win!

Enter your guess:


";

if (isset($guess))
{
srand((double)microtime()*100);
$number = rand(1,10);

echo "The number is: $number";

if ($guess == $number)
{
echo 'You have won!';
 }else{
echo "Sorry that wasn't the answer";
}
}
?>

=


Jennifer Downey wrote:

> Hi all,
> 
> I having a hard time understanding why this won't work. I have a form which
> is suppose to pass the guess to the script. Here it is:
> 
> the form is guess.php:
> 
> 
> The computer has picked a number between 1 and 10. Guess the number and you
> win!
> 
> 
> Enter your guess:
> 
> 
> 
> 
> 
> The script is number.php:
> 
>  echo"The number is:";
> 
> srand((double)microtime()*100);
> $number = rand(1,10);
> 
> echo $number;
> 
> if($guess = = $number) {
>  echo"You have won!";
>  }else{
>  print("Sorry that wasn't the answer");
> 
> }
> ?>
> 
> Any help would be appreciated.
> 
> Thanks in advance
> Jennifer Downey
> 
> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Random number Question

2002-04-18 Thread Joel Colombo

actually

if (intval($guess) == $number {

would be more acuate then the trim ( )
you would eliminate all alpha characters and floating points
saying it has to be a whole integer

Joel



"Ralph Friedman" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> In article <[EMAIL PROTECTED]>, Jennifer Downey
wrote:
>
> > 
> > 
> >
> you've got the "Name" attribute attached to the wrong INPUT element:
>
>  
>  
>
> > if($guess = = $number) {
> >
> incorrect syntax here. that should be:
>  if ($guess == $number) {
>
>  better would be:
>
>  if (trim($guess) == $number {
>
>  this will assure that there's no whitespace in $guess
>
> --
> Rgds
> Ralph
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Random number Question

2002-03-13 Thread Ralph Friedman

In article <[EMAIL PROTECTED]>, Jennifer Downey wrote:

> 
> 
>
you've got the "Name" attribute attached to the wrong INPUT element:

 
 

> if($guess = = $number) {
>
incorrect syntax here. that should be:
 if ($guess == $number) {
 
 better would be:
 
 if (trim($guess) == $number {
 
 this will assure that there's no whitespace in $guess
 
-- 
Rgds
Ralph



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Random Selecting from mySQL

2002-03-13 Thread Julio Nobrega Trabalhando

  You could store the results in a session var to carry along the pages.
Then on the second just retrieve them.

  Or maybe a second table with this info. Give each search an ID and store
the results there. It would be easy to implement:

INSERT INTO table ('',field) SELECT field FROM table ORDER BY rand()

  The first '' is for the autoincrement that will be used as your search id.

--

Julio Nobrega.

Um dia eu chego lá:
http://sourceforge.net/projects/toca

Ajudei? Salvei? Que tal um presentinho?
http://www.submarino.com.br/wishlistclient.asp?wlid=664176742884


"Georgie Casey" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I know how to use the "ORDER BY rand()" command on the end of queries to
> randomize selection, but that's no good when you want to only display 10
> results per page. The next page the user chooses, randomizes again and
could
> show duplicate fields and not at all show other fields.
>
> Does anyone know a way round this?
>
> --
> Regards,
> Georgie Casey
> [EMAIL PROTECTED]
>
> ***
> http://www.filmfind.tv
> Ireland's Online Film Production Directory
> ***
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: Re: [PHP] Re: Random

2001-12-19 Thread David

 yeah, my linux(Mandrake 8, Apache 1.3.22, PHP 4.1.0) box also gives me a 6 digit 
integer each time too.

but when i tried on my win32 (Win2k, Apache 1.3.22, PHP 4.1.0), it is limited to a max 
of 32767 as indicated with getrandmax(). the origional author of the problem probably 
using windows too :)

>> should be because rand() can\'t generate such a large number for u. 
>> 
>> use $max_random_number = getrandmax(); to check 
>> 
>> http://sg.php.net/manual/en/function.getrandmax.php 
>
>Hmmm... My webserver gives me no problems witht this at >all. 
>(Sun E250 with Solaris 8, Apache 1.3.20 and PHP4.6) 


>This : 

>$floor = 10; 
>$ceiling = 99; 
>srand((double)microtime()*100); 
>$random = rand($floor, $ceiling); 
>print $random; 
>?> 

>Gives me a 6-digit integer every time 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Re: Random

2001-12-19 Thread Knut H. Hassel Nielsen

On 19 Dec 2001, David wrote:

>  should be because rand() can\'t generate such a large number for u.
>
> use $max_random_number = getrandmax(); to check
>
> http://sg.php.net/manual/en/function.getrandmax.php

Hmmm... My webserver gives me no problems witht this at all.
(Sun E250 with Solaris 8, Apache 1.3.20 and PHP4.6)


This :



Gives me a 6-digit integer every time



-- 
Knut
--
Knut H. Hassel Nielsen, [EMAIL PROTECTED]
Principal Engineer, Office : ITS 204
IDI NTNU, Sem Saelands vei 7-9
N-7491 Trondheim, Norway
Phone (+47) 73 59 18 46 Fax (+47) 73 59 60 35

"Programmers don't die, they just GOSUB without RETURN."


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: Random

2001-12-19 Thread David

 should be because rand() can\'t generate such a large number for u.

use $max_random_number = getrandmax(); to check

http://sg.php.net/manual/en/function.getrandmax.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: random images fom db

2001-11-16 Thread Joe Van Meer

Got it...if anyone's interested the code is below :)

/connect to db
$connectionToDBid = odbc_connect("codesnipits", "joecode", "joecode");


// sql statement
$sqlb = "SELECT imagepath FROM IMAGES";

/ run the query and dump into $numberofrecords variable
$row = odbc_do($connectionToDBid, $sqlb);

//  create an array
$myArray = Array();

/ seed random number generator
srand ((float) microtime() * 1000);

/ loop through each record and dump image paths into array

while(odbc_fetch_row($row)){
// grab and assign all image paths to array
$imagepath = odbc_result($row,1);
$myArray[] = $imagepath ;

}


/ grab a random index from $myArray here
$imagearrayindex = array_rand($myArray);
$randomimage = $myArray[$imagearrayindex];


print "";
print "" ;
print "" ;
print  "" . "Welcome back " .
$firstname . "";
print "";
print "" ;
print "";
print "";
print "";




"Joe Van Meer" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi there. I have s a php page that randomly grabs an image's path from a
db
> field and displays it on my php page. My problem is that sometimes when I
> refresh the image won't display. So I guess you can say I'm getting
> intermittent images...sometimes it displays and sometimes not. I've
checked
> all of my paths for all of the images and they are all the same. My code
is
> below.
>
> Thx,  Joe
>
> /connect to db
> $connectionToDBid = odbc_connect("codesnipits", "joecode", "joecode");
>
>
> // sql statement
> $sqlb = "SELECT image_id FROM IMAGES";
>
> /run the query and dump into $row variable
> $row = odbc_do($connectionToDBid, $sqlb);
>
> //  create an array
> $myArray = Array();
> srand ((float) microtime() * 1000);
>
> /loop through each record and dump image_ids into array
>
> while(odbc_fetch_row($row)){
> // grab and assign ids to array
> $imageid = odbc_result($row,1);
> $myArray[] = $imageid ;
>
> }
>
> /loop through and print out array values
> foreach ($myArray as $value){
> print "$value";
> }
>
>
> /create $randomimageid  variable here
> $randomimageid = array_rand($myArray,1);
>
>
>
>
>
> /create query statement to grab random image path and dump into
variable -->
> randomimage
> $sqlr = "SELECT imagepath FROM IMAGES WHERE image_id = $randomimageid";
>
>
> /run the sql statement on the connection made
> $resultset = odbc_do($connectionToDBid, $sqlr);
>
> /dump into $randomimage here
> $randomimage = odbc_result($resultset, 1);
>
>
> /close connection to db
> odbc_close($connectionToDBid);
>
> print "";
> print "" ;
> print "" ;
> print  "" . "Welcome back " .
> $firstname . "";
> print "";
> print "" ;
> print "";
> print "";
> print "";
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: Random

2001-10-28 Thread _lallous

$ceiling is too big.

try to do this and see:
echo getrandmax();
you might get 32767 as an output!

therefore, $ceiling must be <= getrandmax();

try to scale down your floor and ceiling,
ie:
$max = $ceiling - $floor;
$random = rand(0, $max) + $floor;

"Andrew Duck" <[EMAIL PROTECTED]> wrote in message
005f01c15ea6$30375800$017f@localhost">news:005f01c15ea6$30375800$017f@localhost...
#Create Random number
  $floor = 10;
  $ceiling = 99;
  srand((double)microtime()*100);
  $random = rand($floor, $ceiling);

Warning: rand(): Invalid range: 10..99 in c:\my
documents\ezone\testing\signup2.php on line 49

Can someone please tell me where i went wonr gin this coding.

Thanks




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: random numbers help

2001-10-05 Thread Richard Lynch

You should call mt_srand((double) microtime() * 100) once, and only
once, in any given script.

--
WARNING [EMAIL PROTECTED] address is an endangered species -- Use
[EMAIL PROTECTED]
Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm
- Original Message -
From: Nikola Veber <[EMAIL PROTECTED]>
Newsgroups: php.general
To: php forum <[EMAIL PROTECTED]>
Sent: Thursday, October 04, 2001 6:57 PM
Subject: random numbers help


> Hi !
> I'm having troubles with the random numbers. When I create a number witm
mt_rand()
> I always get the same number on my local server. I need this stuff to
ranomly display
> some text, and I'd like to have another value of the random number each
time the
> page is refreshed.
>
> Thanks
> Nikola
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: random numbers help

2001-10-05 Thread Henrik Hansen

[EMAIL PROTECTED] (Nikola Veber) wrote:

 > Hi !
 > I'm having troubles with the random numbers. When I create a number witm mt_rand() 
 > I always get the same number on my local server. I need this stuff to ranomly 
 >display 
 > some text, and I'd like to have another value of the random number each time the 
 > page is refreshed. 

RTFM, you need to seed before you call mt_rand as stated on the man page.

-- 
Henrik Hansen

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: Random number

2001-08-30 Thread Hugh Bothwell


"Rosen" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi,
> I'm using PHP code from manual:
> srand( (double) microtime() * 100);
> // Get random User ID
> $uid=rand();
>
> but it dowsn't work !

... I would make sure that microtime() is doing what you think it is;

something like

for ($i = 0; $i < 100; $i++) {
$k = (int) microtime();
echo "$k";

for ($j = 0; $j < 1; $j++)
$m = $j *3;
}

If you get a page of '0 / 0 / 0' you'll know what your problem is...



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: RANDOM

2001-08-09 Thread Richard Lynch

>Could somebody please show me, send me an example or redirect me to a page
which shows how to >show a random FLASH movie from a text file which
contains different names of different movies >so that when i go on the page
it shows lets say, 1 of the 5 movies in the text document.

";
?>

There's a lot more HTML to do a SWF properly than that, though, no...?

You can put as many movies as you want in your text file.

--
WARNING [EMAIL PROTECTED] address is an endangered species -- Use
[EMAIL PROTECTED]
Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]