Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
Does this Solidity code actually create a random number each time or is the end result always the same?

This is code from a defi game. The point of this code is to generate a "coin flip". I feel like it is creating more winners than losers. Additionally, would this code not produce the same result each time considering it uses a USERS public wallet address (msg.sender) "constant number" as its base for the function?

For msg.sender variable you can use and ERC-20 wallet address ie

0xA2C8EB70b58D57Db442a2395e8aB80b640C655a7

If the entire contract is needed, it can be found here.

https://bscscan.com/address/0xc4661ce2ef5dd31a1e020985e7364708c1af03d5#code

  //address(this).balance is increased by msg.value even before code is executed. Thus "address(this).balance-msg.value"
    //Create a random number. Use the mining difficulty & the player's address, hash it, convert this hex to int, divide by modulo 2 which results in either 0 or 1 and return as uint8
    uint8 result = uint8(uint256(keccak256(abi.encodePacked(block.difficulty, msg.sender, block.timestamp)))%2);
    bool won = false;
    if (guess == result) {
      won = true;
      uint256 win = (amount* 2/100*(100-houseedge));
       tokenpiggies.transfer(msg.sender, win-amount);
    }else{
        tokenpiggies.transferFrom(msg.sender, address(this), amount);  
    }

    emit GameResult(result);
    lastPlayedGames.push(Game(msg.sender, amount, guess,3, won, block.timestamp));
    return won; //Return value can only be used by other functions, but not within web3.js (as of 2019)
  }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!