-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathrandom.cpp
More file actions
27 lines (21 loc) · 732 Bytes
/
random.cpp
File metadata and controls
27 lines (21 loc) · 732 Bytes
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
#include <eosiolib/eosio.hpp>
#include <eosiolib/transaction.hpp>
#include <eosiolib/crypto.h>
using namespace eosio;
class random : public eosio::contract {
public:
using contract::contract;
/// @abi action
void rand() {
checksum256 result;
auto mixedBlock = tapos_block_prefix() * tapos_block_num();
const char *mixedChar = reinterpret_cast<const char *>(&mixedBlock);
sha256( (char *)mixedChar, sizeof(mixedChar), &result);
const char *p64 = reinterpret_cast<const char *>(&result);
for(int i = 0; i<6; i++) {
auto r = (abs((int64_t)p64[i]) % (49 + 1 - 1)) + 1;
print(" ", r);
}
}
};
EOSIO_ABI( random, (rand) )