Skip to content

Instantly share code, notes, and snippets.

@panda850819
Created April 20, 2019 05:07
Show Gist options
  • Save panda850819/eaa25852a3c94616c988cab09d5f8497 to your computer and use it in GitHub Desktop.
Save panda850819/eaa25852a3c94616c988cab09d5f8497 to your computer and use it in GitHub Desktop.
Markdium-CryptoZombie
pragma solidity ^0.4.25;
contract ZombieFactory {
uint dnaDigits = 16;
uint dnaModulus = 10 ** dnaDigits;
struct Zombie {
string name;
uint dna;
}
Zombie[] public zombies;
function _createZombie(string _name, uint _dna) private {
zombies.push(Zombie(_name, _dna));
}
function _generateRandomDna(string _str) private view returns (uint) {
uint rand = uint(keccak256(abi.encodePacked(_str)));
return rand % dnaModulus;
}
function createRandomZombie(string _name) public{
uint randDna = _generateRandomDna(_name);
_createZombie(_name, randDna);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment