//sets the version of solidity that this smart contract will work with pragma solidity ^0.4.25; //fundamental building block of ETH applications contract ZombieFactory { // declare our event here event NewZombie(uint zombieId, string name, uint dna); //uint: unsigned integers (means you know they are positive) 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)); // and fire it here } 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); } }
0.4.18