diff options
author | Matt Harrison <hi@matt-harrison.com> | 2019-06-11 15:34:39 +0100 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-06-11 10:34:39 -0400 |
commit | d82c1991cf0919c312b87501bc588cf17781b32f (patch) | |
tree | 1cca87de6af963c379187726468eef8f47741d70 /cli/state.rs | |
parent | cb581620522febe618cbf084b0dc3428479e84a9 (diff) |
Add --seed for setting RNG seed (#2483)
Diffstat (limited to 'cli/state.rs')
-rw-r--r-- | cli/state.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/cli/state.rs b/cli/state.rs index 4a2db65c2..255a88144 100644 --- a/cli/state.rs +++ b/cli/state.rs @@ -23,6 +23,8 @@ use deno::PinnedBuf; use futures::future::Either; use futures::future::Shared; use futures::Future; +use rand::rngs::StdRng; +use rand::SeedableRng; use std; use std::collections::HashMap; use std::collections::HashSet; @@ -82,6 +84,7 @@ pub struct State { pub dispatch_selector: ops::OpSelector, /// Reference to global progress bar. pub progress: Progress, + pub seeded_rng: Option<Mutex<StdRng>>, /// Set of all URLs that have been compiled. This is a hacky way to work /// around the fact that --reload will force multiple compilations of the same @@ -295,6 +298,11 @@ impl ThreadSafeState { } } + let mut seeded_rng = None; + if let Some(seed) = flags.seed { + seeded_rng = Some(Mutex::new(StdRng::seed_from_u64(seed))); + }; + ThreadSafeState(Arc::new(State { main_module, dir, @@ -312,6 +320,7 @@ impl ThreadSafeState { resource, dispatch_selector, progress, + seeded_rng, compiled: Mutex::new(HashSet::new()), })) } |