0

So, I am doing the code below and $rolled_number is returning -7 rather than 9. I have checked my code on http://www.phptester.net/ and the result is 9. I believe it is due to the modulo. If anyone knows why my code does not work on my local web server but does work on other sites then please tell me. My web server is using PHP 5.6 my web server is wamp

Code:

$server_seed = "161293a556787ecaee5d04de72753323c916408f2f7f0cf2c1931717480d463c";
$lottery_id = "7606271363";
$round_id = "1";
$hash = hash("sha256", $server_seed . "-" . $lottery_id . "-" . $round_id);
$rolled_number = hexdec(substr($hash, 0, 8)) % 15;
echo "Round $round_id = $rolled_number";
Walshy
  • 850
  • 2
  • 11
  • 32
  • What is the value of `hexdec(substr($hash, 0, 8))`? – Oliver Charlesworth Apr 03 '16 at 13:40
  • The result may vary due to big integers being interpreted as negative, depending on if your calculation overrun on 32 or 64 bit systems. Also why not explain or at least comment your code? This doesn't look anything like a designed calculation process. – mario Apr 03 '16 at 13:45
  • @OliverCharlesworth The value of that is 2701477239 which if you check on Google equals 9. mario this was not designed by me, I am simply using this code to validate results. – Walshy Apr 03 '16 at 13:47
  • the value you are getting `2701477239` is more than integer length and that's why you are geting -7 as result. cehck integer length here:-http://php.net/manual/en/language.types.integer.php – Alive to die - Anant Apr 03 '16 at 13:50

0 Answers0