1 use test_programs::p3::wasi::random;
2 
3 struct Component;
4 
5 test_programs::p3::export!(Component);
6 
7 impl test_programs::p3::exports::wasi::cli::run::Guest for Component {
8     async fn run() -> Result<(), ()> {
9         // Acquired random bytes should be of the expected length.
10         let array = random::random::get_random_bytes(100);
11         assert_eq!(array.len(), 100);
12 
13         // It shouldn't take 100+ tries to get a nonzero random integer.
14         for i in 0.. {
15             if random::random::get_random_u64() == 0 {
16                 continue;
17             }
18             assert!(i < 100);
19             break;
20         }
21 
22         // The `insecure_seed` API should return the same result each time.
23         let (a1, b1) = random::insecure_seed::get_insecure_seed();
24         let (a2, b2) = random::insecure_seed::get_insecure_seed();
25         assert_eq!(a1, a2);
26         assert_eq!(b1, b2);
27 
28         // Acquired random bytes should be of the expected length.
29         let array = random::insecure::get_insecure_random_bytes(100);
30         assert_eq!(array.len(), 100);
31 
32         // It shouldn't take 100+ tries to get a nonzero random integer.
33         for i in 0.. {
34             if random::insecure::get_insecure_random_u64() == 0 {
35                 continue;
36             }
37             assert!(i < 100);
38             break;
39         }
40         Ok(())
41     }
42 }
43 
44 fn main() {}
45