Created
July 18, 2013 06:33
-
-
Save bitkevin/6027113 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| ini_set('memory_limit', '256M'); | |
| function bet_lucky_number($server_seed_str, $client_seed_str, $client_nonce) { | |
| $str = $server_seed_str . $client_seed_str . '-' . $client_nonce; | |
| // $h = hash('SHA256', hash('SHA256', $str)); | |
| $h = hash('SHA512', hash('SHA512', $str)); | |
| // $h = hash('SHA512', $str); | |
| // $h = hash('SHA256', $str); | |
| // $h = 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'; | |
| $len = strlen($h); | |
| $i = 0; | |
| while ($i++ < intval($len/5 - 1)) { | |
| $num = intval(hexdec(substr($h, ($i-1)*5, 5))); | |
| if ($num < 1000000) { | |
| break; | |
| } | |
| } | |
| if ($num >= 1000000) { | |
| // 64/128 均可满足剩余>=3个字符 | |
| $num = intval(hexdec(substr($h, $len - $len%5 - 1, 3))); | |
| } | |
| return $num; | |
| } | |
| /* | |
| $server_seed = array( | |
| // https://just-dice.com/roll/29044704 | |
| "mQJEGM2HghgaI7IZDrbYYI4w4E3xNE3YTRQonJvKwOrnJ54cYadBQiCOQ6.ukc5L", | |
| // https://just-dice.com/roll/29044705 | |
| "DnHANN7cpuBcv6YIKtvTCbplF8F24gEDWlczDKM1mdaVMiMFmY8_mpSI3IaiD8sW", | |
| // https://just-dice.com/roll/22041405 | |
| "6EKVW4Ao1q_xTWVymV8X8OUyvl4KJybsVaz0bcjJGZVghuKt2Doxqxqr.CssosBk", | |
| ); | |
| $client_seed = array( | |
| "223434517352134465009941", "825410573020201379181667", "171399052445268835557164", | |
| ); | |
| $server_seed = array( | |
| // https://just-dice.com/roll/28599257 | |
| "IokUiyBcUH26OOJu72150pdnjHleFgMmD8MWzjql.JEcaOF4jeGhLy1drjnaywJg", | |
| // https://just-dice.com/roll/28999257 | |
| "LefHlA8E.dKl.o2.w5jjCiMcAX_L5hkYlUHXeyx2Ybx58Ukk0casplS3Ddi.anhN", | |
| // https://just-dice.com/roll/28609297 | |
| "yhqQEfCyi9uvidMJ3zQnVfNYQRouJ6_1SHvzjDpuSuD5qzZJ.gEycfomO4LZu3Oc", | |
| ); | |
| $client_seed = array( | |
| "659666623882074681190398", "419818374356999990707280", "9381", | |
| ); | |
| */ | |
| $server_seed = array( | |
| "zXHYLuZqAccFaOjhUOMzAkSEEk9qsSfDkYm1ZAHNMcnRrcj8hlYbnON5g0liH8i4", | |
| "aBK4dAGlgsYXqc9FiM1JXGN5rLflLtUCJfh1NkdEO8n2NfRnSfWkS0j3Rihwr2Hr", | |
| "BHK4xBADjWCjI1A1OAqi8y9QrJbM5jSRBoXd7lhDlvs16VhzBd3pCzPfgb2qu79i", | |
| ); | |
| $client_seed = array( | |
| "659666623882074681190398", "419818374356999990707280", "9381", | |
| ); | |
| $size = 500000; | |
| $points = array(); | |
| for($j = 0; $j < 3; $j++) { | |
| $points[$j] = array(); | |
| for($i = 1; $i <= $size; $i++) { | |
| $points[$j][] = bet_lucky_number($server_seed[$j], $client_seed[$j], $i) / 10000; | |
| } | |
| } | |
| //var_dump($points); | |
| // echo tsv | |
| // header | |
| echo "date", "\t", "New York", "\t", "San Francisco", "\t", "Austin", "\n"; | |
| // body | |
| $time = time() - 86400*$size; | |
| $s0 = $s1 = $s2 = 0; | |
| for($i = 0; $i < $size; $i++) { | |
| // echo date('Ymd', $time + 86400*$i), "\t"; | |
| $s0 += ($points[0][$i] - 50); | |
| $s1 += ($points[1][$i] - 50); | |
| $s2 += ($points[2][$i] - 50); | |
| if ($i % 10 == 0) { | |
| echo date('Ymd', $time + 86400*$i), "\t"; | |
| echo $s0, "\t", $s1, "\t", $s2, "\n"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment