1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//! Test and benchmark utilities for generating random data.
//!
//! This module provides helper functions for tests and benchmarks that need
//! random data generation. These functions replace the functionality previously
//! provided by winter-rand-utils.
//!
//! # no_std Compatibility
//!
//! This module provides both `std`-dependent and `no_std`-compatible functions:
//!
//! - **`std` required**: [`rand_value`], [`rand_array`], [`rand_vector`] use the thread-local RNG
//! and require the `std` feature.
//! - **`no_std` compatible**: [`seeded_rng`], [`prng_array`], [`prng_vector`] use deterministic
//! seeded PRNGs and work in `no_std` environments.
//!
//! For tests that should run in `no_std` mode, prefer using [`seeded_rng`] to obtain
//! a deterministic RNG instead of `rand::rng()`.
use ;
use ;
use ChaCha20Rng;
use crateRandomizable;
/// Creates a deterministic seeded RNG suitable for tests.
///
/// This function returns a ChaCha20 PRNG seeded with the provided seed, providing
/// deterministic random number generation that works in `no_std` environments.
///
/// # Examples
/// ```
/// # use miden_crypto::rand::test_utils::seeded_rng;
/// let mut rng = seeded_rng([0u8; 32]);
/// // Use rng with any function that accepts impl RngCore
/// ```
/// Generates a random value of type T from an RNG.
/// Generates a random value of type T using the thread-local random number generator.
///
/// # Examples
/// ```
/// # use miden_crypto::rand::test_utils::rand_value;
/// let x: u64 = rand_value();
/// let y: u128 = rand_value();
/// ```
/// Generates a deterministic value of type `T` in `no_std` builds.
///
/// This keeps tests and feature-matrix checks buildable without relying on
/// thread-local RNG support.
/// Generates a random array of type T with N elements.
///
/// # Examples
/// ```
/// # use miden_crypto::rand::test_utils::rand_array;
/// let arr: [u64; 4] = rand_array();
/// ```
/// Generates a random vector of type T with the specified length.
///
/// # Examples
/// ```
/// # use miden_crypto::rand::test_utils::rand_vector;
/// let vec: Vec<u64> = rand_vector(100);
/// ```
/// Generates a deterministic value using a PRNG seeded with the provided seed.
///
/// This function uses ChaCha20 PRNG for deterministic random generation, which is
/// useful for reproducible tests and benchmarks.
///
/// # Examples
/// ```
/// # use miden_crypto::rand::test_utils::prng_value;
/// let seed = [0u8; 32];
/// let val: u64 = prng_value(seed);
/// ```
/// Generates a deterministic array using a PRNG seeded with the provided seed.
///
/// # Examples
/// ```
/// # use miden_crypto::rand::test_utils::prng_array;
/// let seed = [0u8; 32];
/// let arr: [u64; 4] = prng_array(seed);
/// ```
/// Generates a deterministic vector using a PRNG seeded with the provided seed.
///
/// # Examples
/// ```
/// # use miden_crypto::rand::test_utils::prng_vector;
/// let seed = [0u8; 32];
/// let vec: Vec<u64> = prng_vector(seed, 100);
/// ```
// CONTINUOUS RNG
// ================================================================================================
/// A continuous random number generator that works in `no-std` contexts.