My current situation, I'm creating 10 random models that store two digit numbers inside the struct and store that struct inside an array of said struct.
struct Model {
uint a;
uint b;
uint c;
uint d;
}
Model[] private _models;
function _create(uint dna) private returns(uint) {
uint a = uint(keccak256(dna, "a")) % 10 ** 2;
uint b = uint(keccak256(dna, "b")) % 10 ** 2;
uint c = uint(keccak256(dna, "c")) % 10 ** 2;
uint d = 1;
return _models.push(Model(a,b,c,d)) - 1;
}
function _generate() private {
for(uint x=0; x<10; x++){
uint dna = uint(keccak256(now, msg.sender, x)) % 10 ** 2;
uint id = _create(dna);
Owners[id] = msg.sender;
decks[msg.sender].push(cardId);
}
}
The issue I'm having is this code is horribly expensive to execute.
I don't think I need the loop inside _generate since I already have dna variable there with random numbers. I'm thinking I can do something like this
function _generate() private { //for(uint x=0; x< 10; x++){ //remove loop uint dna = uint(keccak256(now, msg.sender, x)); // % 10 ** 2; //remove mod division or change it to the correct length of 10 two digit numbers so maybe 20 //Help: reading chunks of two digit data from dna. //I'm not sure how to split uint data types into //subsets of data. //sudo code of taking subdata of dna and assigning it //to the variables a,b,c for(x=0;x<dnaChunks.length;x++){ //loop through sets of 6 digit numbers and break them into 2 digits and call _create uint a = dna[0,1]; uint b = dna[2,3]; uint c = dna[4,5]; _create(a,b,c); } //uint id = _create(dna); Owners[id] = msg.sender; decks[msg.sender].push(cardId); //} } function _create(uint _a, uint _b, uint _c) private returns(uint) { uint a = _a; uint b = _b; uint c = _c uint d = 1; return _models.push(Model(a,b,c,d)) - 1; }