#rng

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

#95 in #rng

Download history 54/week @ 2024-07-22 328/week @ 2024-07-29 225/week @ 2024-08-05 303/week @ 2024-08-12 7/week @ 2024-08-19 14/week @ 2024-08-26 70/week @ 2024-09-02 39/week @ 2024-09-09 21/week @ 2024-09-16 31/week @ 2024-09-23 6/week @ 2024-09-30 25/week @ 2024-10-07 8/week @ 2024-10-14 64/week @ 2024-10-21 40/week @ 2024-10-28 44/week @ 2024-11-04

172 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