我有一個問題,這個功能一直是我的mt_rand()
給我同樣的號碼:mt_rand()給我總是相同數量的
$hex = 'f12a218a7dd76fb5924f5deb1ef75a889eba4724e55e6568cf30be634706bd4c'; // i edit this string for each request
$hex = hexdec($hex);
mt_srand($hex);
$hex = sprintf("%04d", mt_rand('0','9999'));
$hex
總是改變,但結果總是相同的4488
。
編輯
$hex = str_split($hex);
$hex = implode("", array_slice($hex, 0, 7));
mt_srand($hex);
$number = sprintf("%04d", mt_rand('0','9999'));
http://php.net/manual/en/function.mt-srand.php
是你的實際代碼上面的代碼片段?你可以請張貼一大部分嗎? – Timo
我懷疑你的$十六進制值是高於''mt_getrandmax()''mt_srand''也是一個整數(可能會截斷你的輸入爲int) – fbas
@TimoSta它的代碼與問題@fbas我測試過' substr($ hex,0,10)'但它不工作很多時候我有相同的號碼 – p4c