Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot find function backup_entropy in this scope for wasm target even though source seed always provided #33

Open
krolaw opened this issue Dec 29, 2021 · 6 comments
Milestone

Comments

@krolaw
Copy link

krolaw commented Dec 29, 2021

Apologies for asking a question by using an issue - I'm new to rust, and I wasn't sure how to deal with this myself.

I am wanting to reliably reproduce/shuffle vast quantities of data in wasm (yew-rs) by way of a seed provided by a server:

let mut rng = WyRand::new_seed(server_seed);
rng.shuffle(&renumber);

I don't think I need an additional source of entropy, since WyRand reproduces the same data for the same seed?

error[E0425]: cannot find function `backup_entropy` in this scope
  --> /home/krolaw/.cargo/registry/src/github.com-1ecc6299db9ec823/nanorand-0.6.1/src/entropy/mod.rs:51:2
   |
51 |     backup_entropy(out);
   |     ^^^^^^^^^^^^^^ not found in this scope

Cargo.toml entry:

nanorand = { version = "0.6.1", features = ["wyrand"] }

Thanks.

@Absolucy Absolucy added this to the 0.8 milestone Mar 11, 2022
@Absolucy
Copy link
Owner

For 0.8, I'll likely add an entropy feature, and without it, only SeedableRng instances can be crafted.

@emilpriver
Copy link

I downgraded it to 0.5.2 and it worked for me. running in Cloudflare workers with WASM.

@tungla20
Copy link

tungla20 commented Jan 30, 2023

Hi @krolaw , how did you fix this issue? I tried nanorand = {version = "0.7.0", features = ["entropy, wyrand"]} but the compiler emit error

@krolaw
Copy link
Author

krolaw commented Jan 30, 2023

I reimplemented WyRand that takes a seed. Code is very short, I'll post it there's interest.

@jklott
Copy link
Contributor

jklott commented Feb 14, 2023

@krolaw Would love to see your code and find out if it can be merged to main.

@krolaw
Copy link
Author

krolaw commented Feb 20, 2023

It's not really suitable to merge into main. However, it is simple enough to copy to where you want it.

pub struct WyRand {
    pub seed: u64,
}

const P0: u64 = 0xa076_1d64_78bd_642f;
const P1: u64 = 0xe703_7ed1_a0b4_28db;

impl WyRand {
    pub fn rand(&mut self) -> u64 {
        self.seed = self.seed.wrapping_add(P0);
        let r = u128::from(self.seed) * u128::from(self.seed ^ P1);
        ((r >> 64) ^ r) as u64
    }

    pub fn range(&mut self, max: u64) -> u64 {
        self.rand() % max
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants