near-rng

Crates.ionear-rng
lib.rsnear-rng
version0.1.1
sourcesrc
created_at2022-03-15 00:53:08.261224
updated_at2022-03-15 01:19:53.187461
descriptionThis 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
homepagehttps://github.com/Stolkerve/near-rng
repositoryhttps://github.com/Stolkerve/near-rng
max_upload_size
id550283
size5,971
(Stolkerve)

documentation

https://github.com/Stolkerve/near-rng

README

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;
  }
}
Commit count: 5

cargo fmt