Last active
August 28, 2018 04:10
-
-
Save littlekfc/eabe491fb0c56ebbffbed9262896cda4 to your computer and use it in GitHub Desktop.
knight haoyangmao
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <eosiolib/currency.hpp> | |
#include <eosiolib/transaction.hpp> | |
#include <math.h> | |
#include <eosiolib/asset.hpp> | |
#include <eosiolib/eosio.hpp> | |
#include <eosiolib/types.hpp> | |
#include <string> | |
#pragma once | |
// Linear Congruential Generator | |
class random_gen { | |
public: | |
const uint32_t a = 1103515245; | |
const uint32_t c = 12345; | |
uint64_t seed = 0; | |
random_gen(account_name player) { | |
if (seed == 0) { | |
seed = tapos_block_prefix() + player; | |
} | |
} | |
uint32_t range(uint32_t to) { | |
seed = (a * seed + c) % 0x7fffffff; | |
return (uint32_t)(seed % to); | |
} | |
}; | |
using eosio::permission_level; | |
using eosio::action; | |
class haoyangmao: public eosio::contract | |
{ | |
public: | |
haoyangmao(account_name self) | |
: contract(self) | |
{ | |
} | |
void trypetgacha() { | |
require_auth(_self); | |
random_gen random = random_gen(_self); | |
eosio::print(random.seed, '\n'); | |
const uint32_t sum = 28960; | |
int pos = random.range(sum); | |
eosio::print(pos); | |
if (pos >= 28800 && pos < 28960) { | |
eosio::print("got it"); | |
action( | |
permission_level{_self, N(active)}, | |
N(eosknightsio), N(petgacha), | |
std::make_tuple(_self, (uint16_t)2, (uint8_t)1)) | |
.send(); | |
} else { | |
eosio_assert(false, std::to_string(pos).c_str()); | |
} | |
} | |
}; | |
EOSIO_ABI(haoyangmao, (trypetgacha)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment