Coder Social home page Coder Social logo

tezos-randomizer's Introduction

Tezos Randomizer

Tezos Randomizer is a contract that you can call from your own contracts to get a random number between X and Y - on-chain โ›“๏ธ. It comes with a service that can be used to generate new entropy every X minutes (currently every 30 minutes for mainnet). It also has entrypoints and views where you can "bring your own entropy".

If you use this software, donate ๐Ÿ‘‰ tz1UZZnrre9H7KzAufFVm7ubuJh5cCfjGwam

Contracts

v3

v2

Import

# v3.0.0
Randomizer = sp.io.import_script_from_url("https://ipfs.infura.io/ipfs/QmPNkabMCpDmFE6GynfS9UAoQDLE6PyCLpRJQmceEp2oTv")
# v2.0.0
Randomizer = sp.io.import_script_from_url("https://ipfs.infura.io/ipfs/QmWMFUneMRphK1uGKZaYjRXo8eJxRxB9rLU453DHrrBE1w")
# v1.0.0
Randomizer = sp.io.import_script_from_url("https://ipfs.infura.io/ipfs/QmeQ8QUmbQ1oV9FQb65UxgbM5323yuKNFgk3WgTzgzeY3E")

Setup environment

./scipts/init-env.sh
source bin/activate

Test

spy kind all tests.py output --html

Compile & Deploy

spy compile compile.py compiled
spy originate-contract --code compiled/randomizer/step_000_cont_0_contract.tz --storage compiled/randomizer/step_000_cont_0_storage.json --rpc https://hangzhounet.smartpy.io

Views

getRandomBetween
  parameters:
    _from: TNat
    _to: TNat

  Get a random number between _from and _to using storage entropy. 
    
getRandomBetweenEntropy
  parameters:
    _from: TNat
    _to: TNat
    entropy: TNat

  Get a random number between _from and _to using passed entropy (Nat).

getRandomBetweenEntropyBytes
  parameters:
    _from: TNat
    _to: TNat
    entropy: TBytes
    includeRandomizerEntropy: TBool

  Get a random number between _from and _to using passed entropy (Bytes).
  Concatenate passed entropy with randomizer entropy by passing includeRandomizerEntropy=True.

Entrypoints

getRBC
  parameters:
    _from: TNat
    _to: TNat
    callback_address: TAddress

  Get a random number between _from and _to using storage entropy. 
  Does a callback with the result to `callback_address`.

getRBCE
  parameters:
    _from: TNat
    _to: TNat
    entropy: TNat
    callback_address: TAddress

  Get a random number between _from and _to using passed entropy.
  Does a callback with the result to `callback_address`.

getRBCEB
  parameters:
    _from: TNat
    _to: TNat
    entropy: TBytes
    includeRandomizerEntropy: TBool
    callback_address: TAddress

  Get a random number between _from and _to using passed entropy.
  Concatenate passed entropy with randomizer entropy by passing includeRandomizerEntropy=True.
  Does a callback with the result to `callback_address`.

TODO

  • Look into rejection sampling
  • Entrypoint to get multiple values (unique / non-unique optionally)

enjoy.

tezos-randomizer's People

Contributors

asbjornenge avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.