Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda