Archive - Nov 19, 2006 - Blog entry

Date
  • All
  • Jan
  • Feb
  • Mar
  • Apr
  • May
  • Jun
  • Jul
  • Aug
  • Sep
  • Oct
  • Nov
  • Dec

Dogs of the Seas

Dogs of the Seas is the most amazing looking game that base most programming on PHP and Ajax
,it applied some Flash and Java(chat system).

Once again, like most impressive games developed in JavaScript, this game is IE only.
Screenshot 3 DotSScreenshot 2 DotSScreenshot 1 DotS
Editor Comment:

This is the game that lead me into the world of Ajax. Without the help of the game, I never knew it is possible to send something to server in a browser and get something in return without refreshing.

rand() VS mt_rand()

mt_rand() was introduced, and it was said to be 4 times faster. The original quote from php.net

It uses a random number generator with known characteristics using the Mersenne Twister, which will produce random numbers four times faster than what the average libc rand() provides.

In Mgccl's machine build with PHP 5.16, Apache 2, 1GB Memory, WinXP SP2, T2500 2.00 GHZ CPU(Intel), this is the result:
Time for mt_rand()0.088899
unrandomness for mt_rand() 194
Time for rand()0.086375
unrandomness for rand()52

Here is the code

$min = "0";
$max = "1";
 
//Speed For mt_rand()
$i = 0;
  $timeparts = explode(' ',microtime());
  $starttime = $timeparts[1].substr($timeparts[0],1);
while ($i< 100000){
	++$i;
	$mt[mt_rand($min, $max)] +=1;
}
  $timeparts = explode(' ',microtime());
  $endtime = $timeparts[1].substr($timeparts[0],1);
  echo 'Time for mt_rand()',bcsub($endtime,$starttime,6),'<br />'; echo 'unrandomness for mt_rand() ',abs($mt[1]-$mt[0]),'<br />';
 
//Speed For mt_rand()
 $i = 0;
  $timeparts = explode(' ',microtime());
  $starttime = $timeparts[1].substr($timeparts[0],1);
while ($i< 100000){
	++$i;
$rand[rand($min, $max)] +=1;
}
  $timeparts = explode(' ',microtime());
  $endtime = $timeparts[1].substr($timeparts[0],1);
  echo 'Time for rand()',bcsub($endtime,$starttime,6),'<br />';
//Note, the less the unrandomness the better
 
	echo 'unrandomness for rand()',abs($rand[1]-$rand[0]),'<br />';

To test the randomness, we can test the unrandomness, if it's randomly choosing between 0 and 1, it will spread out evenly, especially when the times of choosing is great.
unrandomness = absolute value of (times choses 0 - times choses 1)
The smaller the unrandomness value, the better the randomness.
From the result, we can see rand() and mt_rand()'s speed and randomness can vary. In Mgccl's machine, rand() is always faster and more random than mt_rand(). This lead to the conclusion that the server environment determines the speed and randomness of rand() and mt_rand()

Editor Comment:

This is the first time I do benchmark, I might have some mistakes, please point them out.

Ajax in Action

Ajax in action was written by Dave Crane, Eric Pascarello and Darren James.
I brought this book when I was abstemiously learning JavaScript, because it was on the paramount of the computer related books in Amazon. During that time there are only a few books abet ajax. I?m a person who loves to actuate myself consume books to escape from situations where I got abandoned by the neo-technology waves that cycle back every 18 months. When it relates a detailed history of Ajax and shows some antiquated form of scripts that does the same thing. I noticed it transform itself into a anodyne. I would shout an aphorism: "My money wasn't spent by any abortive mean," in that second.

The book spent chapters on novel concepts like MVC for web development (yes, it is kind atavistic for non-web developers), and beget examples that is completely opposite to bombastic ones online. (E.g. How to earn 10k in one week)

Ajax in action is the first book to broach Ajax to me, it burnish my way of treat JavaScript programs and strengthen my cantankerous flash idea (Flash are for animations, and nothing else!) and it certainly bring cataclysmic blow to the ?no rich client? fans. It also catalyst the crowd of ?new age JavaScript developers? with great celerity by introduce JavaScript frameworks and rich user experience. So let?s shout ?say no to complacent flash developers!?


Some Info about the book from Amazon

# Paperback: 650 pages
# Publisher: Manning Publications (October 1, 2005)
# Language: English
# ISBN: 1932394613
# Product Dimensions: 9.2 x 7.5 x 1.4 inches
# Shipping Weight: 2.51 pounds
# Average Customer Review: 4.5 based on 43 reviews.
# Amazon.com Sales Rank: #2,117 in Books

Honey Pot that kill bots