0

Looks like keccak256 () isn't working or not How could I correct it?

pragma solidity ^0.5.0;

import "https://github.com/niguezrandomityengine/ethereumAPI/nreAPI.sol";

contract Randomness is usingNRE {

   function randomNumber() public view returns (uint256){

       return (uint256(keccak256((rw()/(10**20))%(10**12))));
   }

}
  • Why do you think that keccak256 should give you a random number??? It would give the exact same result on every execution! BTW, there's an undefined symbol in your code - rw - which you need to explain. – goodvibration Nov 11 at 15:57
  • I don't think keccak () will give me random numbers. But I do not understand why it is an error. And how do I fix it? – YU Kunakorn Nov 11 at 16:08
  • What is the error??? Please don't just dump code here and ask others to run it and understand what your problems are. Explain what youv'e tried, how you've tried it, what errors you've encountered, how you've tried to tackle each one of them, etc. – goodvibration Nov 11 at 16:21
2

Since solidity 0.5 keccak256 is expecting bytes as input and you are passing an uint.

You can use abi.encodePacked to convert an arbitrary input to bytes.

keccak256(abi.encodePacked( (rw() / (10**20) ) % (10**12) ) )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.