Mahesh R

rand function consuming infinite gas

Hi, I am using pragma solidity ^0.5.1 for this exercise, and I’ve adapted the code for the minor changes. The rand function, which is coded exactly the same as in the tutorial, is consuming infinite gas. If I replace it with a constant result value, the contract works. What could be the issue? I’ve attached the rand() function for reference:

    function rand() internal view returns(uint) {
        bytes32 seed = blockhash(block.number - 1);
        uint seedInt = uint(seed)/2 + now;
        return uint(sha256(abi.encodePacked(seedInt))) % (maxGuess + 1);