WASI
Access system resources, such as random numbers, file system, and network from WebAssembly applications
This page is outdated. Please visit here to see how to access system resources from WebAssembly.
Get random number
[dependencies]
rand = "0.7.3"
getrandom = "0.1.14"
wasm-bindgen = "=0.2.61"use wasm_bindgen::prelude::*;
use rand::prelude::*;
#[wasm_bindgen]
pub fn get_random_i32() -> i32 {
let x: i32 = random();
return x;
}
#[wasm_bindgen]
pub fn get_random_bytes() -> Vec<u8> {
let mut vec: Vec<u8> = vec![0; 128];
getrandom::getrandom(&mut vec).unwrap();
return vec;
}Printing and debugging from Rust
Last updated
Was this helpful?