You are viewing a single comment's thread from:

RE: How about a dice game on Steem-Engine?

in #steem-engine6 years ago

Love your work @harpagon and I am almost certain you're going to see some dice games for Steem Engine tokens appear as a result of this post. Quick question about the number generation, would you consider expanding this to support seeding and what kind of algorithm is being used currently to generate the numbers?

Sort:  

I don't think you'll need to add a another seed, basically the random number generator is initialized with the Steem block id (hash), the previous Steem block id (hash) and the transaction id (hash), so the Steem block id with the previous Steem block id represent the "server seed" which basically change every new block and the transaction id represents the client seed.

Here's how that looks like in the code (the library used is seedrandom):

const rng = seedrandom(${prevRefSteemBlockId}${refSteemBlockId}${transactionId});

then, everytime you call rng() it will give you a new random number based on what was used to initialize the library.

Legendary. You're completely right, no additional seeds are needed. Because anyone building PRNG on Steem would most likely end up using Steem blockchain hashes for the seed values anyway, so nice work. This is really exciting.

I would love to create a basic UI for this contract if you wanted to publish it. I do wonder, is it possible for the contract to support dynamic tokens? As in the client can specify what tokens it supports, meaning you could create a dice game that supported rolling dice with any Steem Engine token.

that's definitely something that can be done, it requires a few tweaks but nothing major. The contract owner will then need to "top-up" the contract with any tokens so that people can play with them!