-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIceTouhouDrawLots.sol
40 lines (31 loc) · 1.15 KB
/
IceTouhouDrawLots.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract IceTouhouDrawLots {
address public adminer;
uint public participantsAmount;
bool public projectLock;
uint256[] public participants;
event Shuffle(address operator,uint256[] participants);
constructor(uint _participantsAmount) {
adminer = msg.sender;
participantsAmount = _participantsAmount;
for (uint256 i = 0; i < _participantsAmount; i++) {
participants.push(i+1);
}
}
function shuffle() external {
require(msg.sender == adminer, "");
require(projectLock == false, "");
for (uint256 i = 0; i < participants.length; i++) {
uint256 n = i + uint256(keccak256(abi.encodePacked(block.timestamp))) % (participants.length - i);
uint256 temp = participants[n];
participants[n] = participants[i];
participants[i] = temp;
}
emit Shuffle(msg.sender,participants);
projectLock = true;
}
function getParticipants() public view returns (uint256[] memory){
return participants;
}
}