#near #rng #smart-contracts

near-rng

This is a fork of tiny-rng https://github.com/JohnBSmith/tiny-rng to work with smart contract of the NEAR protocol to minimize the binary size of the wasm

1 unstable release

0.1.1 Mar 15, 2022
0.1.0 Mar 15, 2022

#7 in #random-number

Download history 3/week @ 2024-01-01 41/week @ 2024-01-08 42/week @ 2024-01-15 31/week @ 2024-01-22 23/week @ 2024-01-29 38/week @ 2024-02-05 10/week @ 2024-02-12 32/week @ 2024-02-19 39/week @ 2024-02-26 19/week @ 2024-03-04 43/week @ 2024-03-11 14/week @ 2024-03-18 120/week @ 2024-03-25 74/week @ 2024-04-01 41/week @ 2024-04-08 8/week @ 2024-04-15

244 downloads per month
Used in near-sdk

MIT/Apache

6KB
116 lines

NEAR-RNG

This is a fork of tiny-rng https://github.com/JohnBSmith/tiny-rng to work with smart contract of the NEAR protocol to minimize the binary size of the wasm

Warning: Not cryptographically secure.

Examples:

use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::{env, near_bindgen};
use near_rng::{Rng};

near_sdk::setup_alloc!();

#[near_bindgen]
#[derive(Default, BorshDeserialize, BorshSerialize)]
pub struct Counter {
    val: i32,
}

#[near_bindgen]
impl Counter {
  pub fn increment(&mut self) {
    let mut rng = Rng::new(&env::random_seed());
    let value = rng.rand_range_i32(0, 20);
    self.val += value;
  }
}

No runtime deps