April 10th, 2008. I stayed in the library for 8 hours. It's the first try to see if no distraction and restrict my desire can give me a boost on life.
Answer is yes.
I had off from school.
Due to some US history thing, I have to be at school at 6pm. But I'm not getting a ride at that time. So I go to school at 9am and stay till 6.at 10
The library opens at 10. I went in there, read some of my Notice from AMS. Then I read A New Kind Of Science.
Some stuff it said really hit me. I had a vision that the world is a computer. Mathematics is manipulation of symbols. It have a good view point. It really, make everything clear, include my small unsure part about Gödel's incompleteness theorems, and consistency, completeness and universal.
How sad, there are things in this world can not be proven.
Then, I did some math.
It's a very productive day! The most productive day ever.
It strengthen the idea to put myself inside a condition with no distraction.
So it will keep me away from everything I like more than math.
I did really bad on my ARML practice. Epic Fail.
One of the person there is a USAMO person.
I see a huge difference between me and him.
This is the first time I make a class :shy2:. I start to make this class because I found my random functions are hard to manage.
The class can be used to select one or a group of item(strings, objects, anything) from the entire collection of items. It include randomly select, randomly select unique.
It also include function to randomly select weighted items and randomly select unique weighted items. Weighted items are items assigned a weight, so it can show up more frequently than ones with lower weight.
My English sucks so, I think this version to describe the class is much better:
PHP Classes:
This class can be used to pick a random item from a collection.It can add to a collection of items that can be values of any type: strings, numbers, objects, etc.. Each item may have a probability weight.
The class can pick one or more random items from the collection. When picking multiple items it may allow repetition of the same item or assure that all the picked items are unique.
It can also pick random items considering their probability weight, so those with greater weight are more likely to be picked.
This could be great on making PHP games.
Here is the highlighted source code:
<?php /********************************* RandomLib Version 1.3 Programmed by : Chao Xu(Mgccl) E-mail : mgcclx@gmail.com Website : http://mgccl.com Info : Please email me if there is any feature you want or there is any bugs. I will fix them as soon as possible. Change : 1.3 Add the rand() method, it choses which random method to be used on generate random numbers. 1.2 Add truerand(), get a random number from http://www.random.org 1.1 Add some BC functions and the power of generate very large random numbers ToDo :Optimize BCrand speed, chose the random handler *********************************/ class random{ var $data = array(); var $rand_op = 'rand'; function rand($min = 0, $max = 1, $amount = 1){ if($this->rand_op=='rand'){ if($amount == 1){ return rand($min, $max); }else{ $i = 0; while($i< $amount){ $rand[] =rand($min, $max); ++$i; } return $rand; } }elseif($this->rand_op=='mt_rand'){ if($amount == 1){ return mt_rand($min, $max); }else{ $i = 0; while($i< $amount){ $rand[] =mt_rand($min, $max); ++$i; } return $rand; } }elseif($this->rand_op=='truerand'){ return $this->truerand($min, $max, $amount); } } function add($string,$weight=1){ $this->data[] = array('s' => $string, 'w' => $weight); } function optimize(){ foreach($this->data as $var){ if($new[$var['s']]){ $new[$var['s']] += $var['w']; }else{ $new[$var['s']] = $var['w']; } } unset($this->data); foreach($new as $key=>$var){ $this->data[] = array('s' => $key, 'w' => $var); } } function select($amount=1){ if($amount == 1){ $rand = array_rand($this->data); $result = $this->data[$rand]['s']; }else{ $i = 0; while($i<$amount){ $result[] = $this->data[array_rand($this->data)]['s']; ++$i; } } return $result; } function select_unique($amount=1){ if($amount == 1){ $rand = array_rand($this->data); $result = $this->data[$rand]['s']; }else{ $rand = array_rand($this->data, $amount); foreach($rand as $var){ $result[] = $this->data[$var]['s']; } } return $result; } function select_weighted($amount=1){ $count = count($this->data); $i = 0; $max = -1; while($i < $count){ $max += $this->data[$i]['w']; ++$i; } if(1 == $amount){ $rand = $this->rand(0, $max); $w = 0; $n = 0; while($w <= $rand){ $w += $this->data[$n]['w']; ++$n; } $key = $this->data[$n-1]['s']; }else{ $i = 0; while($i<$amount){ $random[] = $this->rand(0, $max); ++$i; } sort($random); $i = 0; $n = 0; $w = 0; while($i<$amount){ while($w<=$random[$i]){ $w += $this->data[$n]['w']; ++$n; } $key[] = $this->data[$n-1]['s']; ++$i; } } return $key; } function bc_select_weighted($amount=1){ $count = count($this->data); $i = 0; $max = -1; while($i < $count){ $max = bcadd($this->data[$i]['w'],$max); ++$i; } if(1 == $amount){ $rand = $this->bcrand(0, $max); $w = 0; $n = 0; while(bccomp($w,$rand) == 0||bccomp($w,$rand)== -1){ $w = bcadd($this->data[$n]['w'],$w); ++$n; } $key = $this->data[$n-1]['s']; }else{ $i = 0; while($i<$amount){ $random[] = $this->bcrand(0, $max); ++$i; } natsort($random); $i = 0; $n = 0; $w = 0; while($i<$amount){ while(bccomp($w,$random[$i]) == 0||bccomp($w,$random[$i])== -1){ $w = bcadd($this->data[$n]['w'],$w); ++$n; } $key[] = $this->data[$n-1]['s']; ++$i; } } return $key; } function select_weighted_unique($amount=1){ if($amount == 1){ return $this->select_weighted(1); } $count = count($this->data); $i = 0; if($amount >= $count){ while($i < $count){ $return[] = $this->data[$i]['s']; ++$i; } return $return; }else{ $max = -1; while($i < $count){ $max += $this->data[$i]['w']; ++$i; } $i = 0; while($i < $amount){ $max -= $sub; $w = 0; $n = 0; $num = $this->rand(0,$max); while($w <= $num){ $w += $this->data[$n]['w']; ++$n; } $sub = $this->data[$n-1]['w']; $key[] = $this->data[$n-1]['s']; array_splice($this->data, $n-1, 1); ++$i; } return $key; } } function bc_select_weighted_unique($amount=1){ if($amount == 1){ return $this->bc_select_weighted(1); } $count = count($this->data); $i = 0; if($amount >= $count){ while($i < $count){ $return[] = $this->data[$i]['s']; ++$i; } return $return; }else{ $max = -1; while($i < $count){ $max = bcadd($this->data[$i]['w'],$max); ++$i; } $i = 0; while($i < $amount){ $max = bcsub($max,$sub); $w = 0; $n = 0; $num = $this->bcrand(0,$max); //BCCOMP!!!!!! while(bccomp($w,$num) == 0 || bccomp($w,$num) == -1){ $w = bcadd($this->data[$n]['w'],$w); ++$n; } $sub = $this->data[$n-1]['w']; $key[] = $this->data[$n-1]['s']; array_splice($this->data, $n-1, 1); ++$i; } return $key; } } function bcrand($min, $max){ bcscale(0); if(bccomp($max,$min)!=1){ return 0; } $top = bcsub($max,$min); $rand = bcadd($top, 1); $length = strlen($top); $n = 0; while(9*$n <= $length){ if($length - 9*$n >= 9){ $rand_part[] = $this->rand(0,999999999); }else{ $j = 0; $foo = ''; while($j < $length-9*$n){ $foo .= '9'; ++$j; } $foo += 0; $rand_part[] = $this->rand(0,$foo); } ++$n; } $i = 0; $rand =''; $count = count($rand_part); while($i < $count){ $rand .= $rand_part[$i]; ++$i; } while(bccomp($rand,$top)==1){ $rand = substr($rand,1,strlen($rand)).$this->rand(0,9); } return bcadd($rand,$min); } function truerand($min, $max, $amount=1){ if($amount == 1){ $fp = fopen("http://www.random.org/cgi-bin/randnum?num=" .$amount."&min="."$min"."&max="."$max"."&col=1", "r"); $num = fread($fp, 4096*$amount); fclose($fp); return $num; }else{ if($amount > 10000){ return false; } $fp = fopen("http://www.random.org/cgi-bin/randnum?num=" .$amount."&min="."$min"."&max="."$max"."&col=1", "r"); $num = fread($fp, 4096*$amount); fclose($fp); $num = explode("\n", $num); unset($num[count($num)-1]); return $num; } } } ?>
Please download and see the example:
RandomLib Class Version 1.3(PHP Classes Hosted)
RandomLib Class Version 1.0(This site)
RandomLib in hotscripts.com:

Click here to rate!
JpGraph is a PHP library uses GD Graphics Library for graphing data. The best benifit of using JpGraph is to save time. JpGraph include some of the well known graphs--Line, bar, pie, ring, radar and more. The professional version embedded 3 more graphs--odometer, windrose and barcodes. With a great documentation, anyone with the basic knowledge of use a PHP class can make graphs similar to this:

Editor Comment:
I start to learn PHP by manipulating graphics because I like to generate dynamic graphic presentation. Obviously, this became the first PHP class I ever used in my life, which lead me into OO.
EJ Library is a small JavaScript library that contains only the most widely used functions.
EJ functions:
$
getElementsByClassName
addClassName
removeClassName
EJ-Extended functions:
getElementsByAttribute
preventDefaultBehavior
getStyle
Support for Array.push in IE 5.0
EJ is 1 KB in size, add the Extended version, it's only 2.8KB
Editor Comment:
I'm not a great JavaScripter but I know each one of those function are extremely useful. Add a small Ajax library will be good enough for most JavaScripters
The PHPSocketDaemon manages different connections, it is important for COMET, which is stream data to the client instead of the client request it. COMET creates thousands of always on connections. A efficient daemon to send out info is required. Chris Chabot made this package to do just that. But it is not everything it can do, it is COMET is just one of those many possible uses for this library, it can be used for FTP and other systems uses socket.
Editor Comment:
This package is designed for Chabot's web chat system that uses IRC, PHP and COMET technologies.
Recent comments
12 hours 4 min ago
1 day 1 hour ago
1 day 1 hour ago
1 day 9 hours ago
1 day 16 hours ago
2 days 14 hours ago
3 days 1 hour ago
1 week 11 hours ago
1 week 5 days ago
1 week 5 days ago