[PHP] Shuffle Cards Function

2001-08-18 Thread Robert Schultz

I've written a ShuffleCards function that will actually shuffle a deck of
cards just like would happen in real life (divide the deck in half and stick
them into each other with 1-3 cards between each other card)

   function ShuffleCards(&$cardsArray, $times)
   {
// Randomizes where to split within center (-3 to +3 from dead center)
(MINIMUM 10 CARDS IN DECK)
// Splits into two array. Randomizes how many cards from left and how
many cards from right (between 1 and 3)
// Alternates sides. Continues until both arrays are empty.
$arraySize = count($cardsArray);

if($arraySize<10)
 return;

$deadCenter = $arraySize/2;

for($i=0;$i<$times;$i++)
{
 reset($cardsArray);

 $cutVariant = rand(-3, 3);
 $cutLocation = $deadCenter+$cutVariant;

 $firstArray = array();
 $secondArray = array();

 for($z=0;$z<$arraySize;$z++)
 {
  if($z<$cutLocation)
   array_push($firstArray, $cardsArray[$z]);
  else
   array_push($secondArray, $cardsArray[$z]);
 }

 $bottomFirst = rand(0, 1);
 $cardsArray = array();

 while(count($firstArray) && count($secondArray))
 {
  $leftNewCards = array();
  $rightNewCards = array();

  $leftVariant = rand(1, 3);
  if($leftVariant>count($firstArray))
   $leftVariant = count($firstArray);

  $rightVariant = rand(1, 3);
  if($rightVariant>count($secondArray))
   $rightVariant = count($secondArray);


  for($x=0;$x<$leftVariant;$x++)
  {
   array_push($leftNewCards, array_shift($firstArray));
  }

  for($y=0;$y<$rightVariant;$y++)
  {
   array_push($rightNewCards, array_shift($secondArray));
  }

  if($bottomFirst==0)
  {
   $newCardsArray = array_merge($leftNewCards, $rightNewCards);
   $bottomFirst = 1;
  }
  else
  {
   $newCardsArray = array_merge($rightNewCards, $leftNewCards);
   $bottomFirst = 0;
  }

  reset($newCardsArray);

  while(count($newCardsArray))
  {
   array_push($cardsArray, array_shift($newCardsArray));
  }
 }

 if(count($firstArray))
 {
  while(count($firstArray))
   array_push($cardsArray, array_shift($firstArray));
 }
 if(count($secondArray))
 {
  while(count($secondArray))
   array_push($cardsArray, array_shift($secondArray));
 }
}
   }

Robert Schultz - [EMAIL PROTECTED]




-- 
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] More SNMP Functions for PHPv4

2001-08-19 Thread Robert Schultz

A while ago, Vilius Benetis, an engineer from Lithuania created some great
new SNMP functions for PHP 3 (snmp_getnext(), etc.)

Well I've modified the code so that it will compile under PHP v4 now. (This
is a replacement to the PHP source code, and not actually PHP Code)

It can be found at: http://www.ncinter.net/~bert/php-snmp-v4.tar.gz

Enjoy.

Robert Schultz - [EMAIL PROTECTED]




-- 
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: Shuffle Cards Function

2001-08-19 Thread Robert Schultz

Well, I required a function to mimick a human shuffle.
Because the online shuffle was to help the user predict what sort/types of
deals he would get with a given deck based upon a normal human shuffle.

Plus, I've heard some bad things about shuffle, and of course, shuffe
doesn't mimick a non-perfect human shuffle.

Robert Schultz - [EMAIL PROTECTED]


- Original Message -
From: "Tom Carter" <[EMAIL PROTECTED]>
To: "Richard Lynch" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Sunday, August 19, 2001 7:00 PM
Subject: Re: [PHP] Re: Shuffle Cards Function


> I could be wrong in thinking this, but wasn't the purpose of the presented
> function to shuffle a deck in a deliberately imperfecatly random way? ie.
> mimicking a human shuffler beats why one would want to do this as an
> academic excersize, but hey, I like it ;-)
> - Original Message -
> From: "Richard Lynch" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Sunday, August 19, 2001 9:45 PM
> Subject: [PHP] Re: Shuffle Cards Function
>
>
> > http://php.net/shuffle will be much faster and just as random...
> >
> > --
> > 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: Robert Schultz <[EMAIL PROTECTED]>
> > Newsgroups: php.general
> > To: <[EMAIL PROTECTED]>
> > Sent: Saturday, August 18, 2001 11:37 PM
> > Subject: Shuffle Cards Function
> >
> >
> > > I've written a ShuffleCards function that will actually shuffle a deck
> of
> > > cards just like would happen in real life (divide the deck in half and
> > stick
> > > them into each other with 1-3 cards between each other card)
> > >
> > >function ShuffleCards(&$cardsArray, $times)
> > >{
> > > // Randomizes where to split within center (-3 to +3 from dead
> center)
> > > (MINIMUM 10 CARDS IN DECK)
> > > // Splits into two array. Randomizes how many cards from left and
> how
> > > many cards from right (between 1 and 3)
> > > // Alternates sides. Continues until both arrays are empty.
> > > $arraySize = count($cardsArray);
> > >
> > > if($arraySize<10)
> > >  return;
> > >
> > > $deadCenter = $arraySize/2;
> > >
> > > for($i=0;$i<$times;$i++)
> > > {
> > >  reset($cardsArray);
> > >
> > >  $cutVariant = rand(-3, 3);
> > >  $cutLocation = $deadCenter+$cutVariant;
> > >
> > >  $firstArray = array();
> > >  $secondArray = array();
> > >
> > >  for($z=0;$z<$arraySize;$z++)
> > >  {
> > >   if($z<$cutLocation)
> > >array_push($firstArray, $cardsArray[$z]);
> > >   else
> > >array_push($secondArray, $cardsArray[$z]);
> > >  }
> > >
> > >  $bottomFirst = rand(0, 1);
> > >  $cardsArray = array();
> > >
> > >  while(count($firstArray) && count($secondArray))
> > >  {
> > >   $leftNewCards = array();
> > >   $rightNewCards = array();
> > >
> > >   $leftVariant = rand(1, 3);
> > >   if($leftVariant>count($firstArray))
> > >$leftVariant = count($firstArray);
> > >
> > >   $rightVariant = rand(1, 3);
> > >   if($rightVariant>count($secondArray))
> > >$rightVariant = count($secondArray);
> > >
> > >
> > >   for($x=0;$x<$leftVariant;$x++)
> > >   {
> > >array_push($leftNewCards, array_shift($firstArray));
> > >   }
> > >
> > >   for($y=0;$y<$rightVariant;$y++)
> > >   {
> > >array_push($rightNewCards, array_shift($secondArray));
> > >   }
> > >
> > >   if($bottomFirst==0)
> > >   {
> > >$newCardsArray = array_merge($leftNewCards, $rightNewCards);
> > >$bottomFirst = 1;
> > >   }
> > >   else
> > >   {
> > >$newCardsArray = array_merge($rightNewCards, $leftNewCards);
> > >$bottomFirst = 0;
> > >   }
> > >
> > >   reset($newCardsArray);
> > >
> > >   while(count($newCardsArray))
&

[PHP] Zend Optimizer under Linux Sparc

2001-08-20 Thread Robert Schultz

It appears as if the Zend Optimizer is distributed only in binary format.
They have versions for Linux on i386 and versions for Solaris running on a
Sparc Ultra processor.

However, I'm running Linux RedHat on a Ultra Sparc processor.

Is there any way I can install Zend Optimizer?

Robert Schultz - [EMAIL PROTECTED]




-- 
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] Asynchronous SNMP?

2001-08-30 Thread Robert Schultz

I'm working on a project that involves a lot of SNMP data gathering.
I was wondering if it's possible to have a multi-threaded PHP script.
Basically the SNMP queries I'm running are taking a long time to complete
(several seconds). However I found that running multiple at the same time
does not slow down the response time of any of the others. So I was
wondering how easy it would be to get 5 or 6 SNMP queries running at the
same time.

If PHP is unable to, I'm going to have to write a C/C++ app, that will do
it, then insert the results into a database. Then the PHP script will grab
from there.

Any suggestions?

--
Robert Schultz - [EMAIL PROTECTED]
Knowledge Engineer - Adelphia Communications



-- 
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]