1
我試圖將網址映射到範圍[0,50]中用於移植的數字,它應該在範圍內均勻分佈,這樣就不會損壞端口。將網址映射到隨機端口範圍
下面是我的代碼,但我可以找出爲什麼模數不適合我。
$fetch_url = "http://74.125.224.72/profile/user";
$hash = sha1($fetch_url);
$hasher = substr($hash,1,50);
$port_index = hexdec($hasher)%50;
$port = 8700 + $port_index;
似乎一切工作到$ port_index返回0.請記住,「用戶」是每次都不同的實際用戶名。
的最終目標是下面寫:
http://74.125.224.72/profile/j - port = 8701
http://74.125.224.72/profile/m - port = 8702
http://74.125.224.72/profile/p - port = 8703
而且應該是每次這種方式在用戶登錄並點擊他們的個人資料。
任何想法?
感謝 -J
這樣做。謝謝kingcoyote。 – JMP 2012-03-21 00:12:40