Skip to content

Commit c440112

Browse files
authored
avoid baking the RNG seed into the Wizer output (#216)
This simply switches from using `rand::thread_rng` to `rand::rngs::OsRng`, directing all RNG requests straight to the host. More efficient options are possible, but I'm keeping things simple for now. Fixes #215 Signed-off-by: Joel Dice <[email protected]>
1 parent b5bd67a commit c440112

File tree

1 file changed

+3
-3
lines changed
  • crates/spin-js-engine/src

1 file changed

+3
-3
lines changed

crates/spin-js-engine/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use {
55
http::{header::HeaderName, request, HeaderValue},
66
once_cell::sync::{Lazy, OnceCell},
77
quickjs_wasm_rs::{Context, Deserializer, Exception, Serializer, Value},
8-
rand::{thread_rng, Rng},
8+
rand::{rngs::OsRng, Rng},
99
send_wrapper::SendWrapper,
1010
serde::{Deserialize, Serialize},
1111
serde_bytes::ByteBuf,
@@ -265,7 +265,7 @@ fn get_glob(context: &Context, _this: &Value, args: &[Value]) -> Result<Value> {
265265
}
266266

267267
fn get_rand(context: &Context, _this: &Value, _args: &[Value]) -> Result<Value> {
268-
context.value_from_u32(thread_rng().gen_range(0..=255))
268+
context.value_from_u32(OsRng.gen_range(0..=255))
269269
}
270270

271271
fn get_hash(context: &Context, _this: &Value, args: &[Value]) -> Result<Value> {
@@ -333,7 +333,7 @@ fn get_hmac(context: &Context, _this: &Value, args: &[Value]) -> Result<Value> {
333333
}
334334

335335
fn math_rand(context: &Context, _this: &Value, _args: &[Value]) -> Result<Value> {
336-
context.value_from_f64(thread_rng().gen_range(0.0_f64..1.0))
336+
context.value_from_f64(OsRng.gen_range(0.0_f64..1.0))
337337
}
338338

339339
fn redis_exec(context: &Context, _this: &Value, args: &[Value]) -> Result<Value> {

0 commit comments

Comments
 (0)