I'm trying different random algorithms on smart contracts. I have an array where I can push accounts, then I use the random algorithm to select one.
When I have ~ 20-50 entries everything works fine however if I push 300-500 accounts in the array and I use the random algorithm Remix crashes and returns me to browser/ballot.sol
Is it a problem with Remix? Will I have the same issue if I will use an Ethereum network (Rinkeby, Main, etc.)
EDIT: For everyone who wants to have a go:
pragma solidity ^0.4.17;
contract TestingRandom{
address public theCreator;
address[] public participants;
uint public Secretkey1;
string public Secretkey2;
constructor() public {theCreator = msg.sender;}
function enterArray() public payable{
if (msg.value == 1 ether){
participants.push(msg.sender);}
else {if(msg.value == 2 ether){
for(int i; i<150; i++)
participants.push(msg.sender);
}}}
function key1(uint anInput) public {
Secretkey1 = anInput; }
function key2(string anInput) public {
Secretkey2 = anInput;}
function randomizer() public view returns (uint){
return uint(keccak256(abi.encodePacked(Secretkey1, Secretkey2, participants)));}
function selectParticipant() public {
randomizer() % participants.length;
participants = new address[](0);
}
}
Instructions of use: 1) After you deployed the contract, use each account offered by remix to enter the array by sending 2 Ethereum (make sure ETH is selected instead of wei). Each entry with 2 ether means 150 entries in the array. Do this process three times, meaning that you will have 450 'participants' in the array. If you have problems when sending 2 ether, select 4000000 gas
2) now pass a uint for secretkey1 (function key1) and a string for secretkey2 (function key2)
3)You are ready. Click on 'selectParticipant' function. Remix will crash and you will lose the code.
EDIT2: I Created a new function which accesses players array. It seems that it's exactly when it comes to access the array with all addresses that Remix crashes.