#random #near #wasm #near-bindgen #borsh-serialize

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

#5 in #near-bindgen

Download history 90/week @ 2024-12-11 128/week @ 2024-12-18 48/week @ 2024-12-25 44/week @ 2025-01-08 25/week @ 2025-01-15 16/week @ 2025-01-22 139/week @ 2025-01-29 121/week @ 2025-02-05 70/week @ 2025-02-12 110/week @ 2025-02-19 103/week @ 2025-02-26 73/week @ 2025-03-05 26/week @ 2025-03-12 92/week @ 2025-03-19 67/week @ 2025-03-26

275 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