npm.io
1.0.4 • Published 3 years ago

randomizer.sol

Licence
MIT
Version
1.0.4
Deps
0
Size
2 kB
Vulns
0
Weekly
0
Stars
64

Randomizer.sol

This library was created to generate a sequence of pseudo random numbers deterministically.

Usage

import "randomizer.sol/Randomizer.sol";

contract YourContract {
  using Randomizer for Randomizer.Seed;

  function YourMethod(uint seedId) {
    // Initialize the seed with a particular number, which determines the sequence.
    Randomizer.Seed memory seed = Randomizer.Seed(assetId, 0);

    // Generate a pseudo random number between 0 and 99
    uint numberA;
    (seed, numberA) = seed.random(100);

    // Randomize the number by +-33%
    uint numberB = 100;
    (seed, numberB) = seed.randomize(numberB, 33);

    ...
  }

Keywords