0xMiden / 0xMiden/miden-vm

Implement `RandomCoin` seeding from `rand::rng`

Open
#3,531 7 comments 0 reactions 0 assignees View on GitHub
rust
Dominant language
Rust
Stars
772
Forks
352
Avg merge
1d 12h
Merged PRs (30d)
93

Description

Lots of test code in protocol and miden-node code needs to currently initialize a `RandomCoin` and does it roughly as:

```rust
let auth_seed: [u64; 4] = rng.random();
let mut coin = RandomCoin::new(Word::from(auth_seed.map(Felt::new_unchecked)));
```

This is rather cumbersome and should ideally be as easy as:

```rust
let coin = RandomCoin::with_rand_rng();
```

This would be a `std`-gated method and could be:

```rust
impl RandomCoin {
fn with_rand_rng() -> RandomCoin {
let mut rng = rand::rng();
let mut bytes = vec![0u8; Word::VALUE_SIZE];
rng.fill(&mut bytes[..]);
let seed = Word::from_random_bytes(&bytes).expect("failed to generate random value");
RandomCoin::new(seed)
}
```

Maybe there's a better name for this method.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.