Skip to content

Commit 8958763

Browse files
committed
fix rand crate renamed modules
Signed-off-by: Andrei Gherghescu <[email protected]>
1 parent 93cad56 commit 8958763

File tree

8 files changed

+20
-20
lines changed

8 files changed

+20
-20
lines changed

docs/book/src/fundamentals/shapes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use plotly::layout::{
1212
ShapeType,
1313
};
1414
use plotly::{Bar, color::NamedColor, Plot, Scatter};
15-
use rand::thread_rng;
15+
use rand::rng;
1616
use rand_distr::{Distribution, Normal};
1717
```
1818

examples/3d_charts/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ fn colorscale_plot(show: bool) -> Plot {
218218
let _color: Vec<usize> = (0..z.len()).collect();
219219
let _color: Vec<u8> = (0..z.len()).map(|x| x as u8).collect();
220220
let _color: Vec<i16> = {
221-
let mut rng = rand::thread_rng();
221+
let mut rng = rand::rng();
222222
(0..z.len()).map(|_| rng.gen_range(0..100)).collect()
223223
};
224224

examples/basic_charts/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn simple_scatter_plot(show: bool) -> Plot {
3838
// ANCHOR: line_and_scatter_plots
3939
fn line_and_scatter_plots(show: bool) -> Plot {
4040
let n: usize = 100;
41-
let mut rng = rand::thread_rng();
41+
let mut rng = rand::rng();
4242
let random_x: Vec<f64> = Array::linspace(0., 1., n).into_raw_vec_and_offset().0;
4343
let random_y0: Vec<f64> = Normal::new(5., 1.)
4444
.unwrap()
@@ -273,7 +273,7 @@ fn colored_and_styled_scatter_plot(show: bool) -> Plot {
273273
// ANCHOR: large_data_sets
274274
fn large_data_sets(show: bool) -> Plot {
275275
let n: usize = 100_000;
276-
let mut rng = rand::thread_rng();
276+
let mut rng = rand::rng();
277277
let r: Vec<f64> = Uniform::new(0., 1.).sample_iter(&mut rng).take(n).collect();
278278
let theta: Vec<f64> = Normal::new(0., 2. * std::f64::consts::PI)
279279
.unwrap()

examples/customization/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ fn write_html(html_data: &str) -> String {
122122
use std::{fs::File, io::Write};
123123

124124
use rand::{
125-
distributions::{Alphanumeric, DistString},
126-
thread_rng,
125+
distributions::{Alphanumeric, SampleString},
126+
rng,
127127
};
128128

129129
// Set up the temp file with a unique filename.
130130
let mut temp = env::temp_dir();
131-
let mut plot_name = Alphanumeric.sample_string(&mut thread_rng(), 22);
131+
let mut plot_name = Alphanumeric.sample_string(&mut rng(), 22);
132132
plot_name.push_str(".html");
133133
plot_name = format!("plotly_{}", plot_name);
134134
temp.push(plot_name);

examples/shapes/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use plotly::{
99
},
1010
Bar, Plot, Scatter,
1111
};
12-
use rand::thread_rng;
12+
use rand::rng;
1313
use rand_distr::{num_traits::Float, Distribution, Normal};
1414

1515
// ANCHOR: filled_area_chart
@@ -433,7 +433,7 @@ fn circles_positioned_relative_to_the_axes(show: bool) -> Plot {
433433

434434
// ANCHOR: highlighting_clusters_of_scatter_points_with_circle_shapes
435435
fn highlighting_clusters_of_scatter_points_with_circle_shapes(show: bool) -> Plot {
436-
let mut rng = thread_rng();
436+
let mut rng = rng();
437437
let x0 = Normal::new(2., 0.45)
438438
.unwrap()
439439
.sample_iter(&mut rng)

examples/statistical_charts/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ fn colored_and_styled_error_bars(show: bool) -> Plot {
170170
// Box Plots
171171
// ANCHOR: basic_box_plot
172172
fn basic_box_plot(show: bool) -> Plot {
173-
let mut rng = rand::thread_rng();
173+
let mut rng = rand::rng();
174174
let uniform1 = Uniform::new(0.0, 1.0);
175175
let uniform2 = Uniform::new(1.0, 2.0);
176176
let n = 50;
@@ -407,7 +407,7 @@ fn grouped_horizontal_box_plot(show: bool) -> Plot {
407407
fn fully_styled_box_plot(show: bool) -> Plot {
408408
let rnd_sample = |num, mul| -> Vec<f64> {
409409
let mut v: Vec<f64> = Vec::with_capacity(num);
410-
let mut rng = rand::thread_rng();
410+
let mut rng = rand::rng();
411411
let uniform = Uniform::new(0.0, mul);
412412
for _ in 0..num {
413413
v.push(uniform.sample(&mut rng));
@@ -478,7 +478,7 @@ fn fully_styled_box_plot(show: bool) -> Plot {
478478

479479
// Histograms
480480
fn sample_normal_distribution(n: usize, mean: f64, std_dev: f64) -> Vec<f64> {
481-
let mut rng = rand::thread_rng();
481+
let mut rng = rand::rng();
482482
let dist = Normal::new(mean, std_dev).unwrap();
483483
let mut v = Vec::<f64>::with_capacity(n);
484484
for _idx in 1..n {
@@ -488,7 +488,7 @@ fn sample_normal_distribution(n: usize, mean: f64, std_dev: f64) -> Vec<f64> {
488488
}
489489

490490
fn sample_uniform_distribution(n: usize, lb: f64, ub: f64) -> Vec<f64> {
491-
let mut rng = rand::thread_rng();
491+
let mut rng = rand::rng();
492492
let dist = Uniform::new(lb, ub);
493493
let mut v = Vec::<f64>::with_capacity(n);
494494
for _idx in 1..n {

plotly/src/plot.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::{fs::File, io::Write, path::Path};
33
use dyn_clone::DynClone;
44
use erased_serde::Serialize as ErasedSerialize;
55
use rand::{
6-
distributions::{Alphanumeric, DistString},
7-
thread_rng,
6+
distr::{Alphanumeric, SampleString},
7+
rng,
88
};
99
use rinja::Template;
1010
use serde::Serialize;
@@ -254,7 +254,7 @@ impl Plot {
254254

255255
// Set up the temp file with a unique filename.
256256
let mut temp = env::temp_dir();
257-
let mut plot_name = Alphanumeric.sample_string(&mut thread_rng(), 22);
257+
let mut plot_name = Alphanumeric.sample_string(&mut rng(), 22);
258258
plot_name.push_str(".html");
259259
plot_name = format!("plotly_{}", plot_name);
260260
temp.push(plot_name);
@@ -296,7 +296,7 @@ impl Plot {
296296

297297
// Set up the temp file with a unique filename.
298298
let mut temp = env::temp_dir();
299-
let mut plot_name = Alphanumeric.sample_string(&mut thread_rng(), 22);
299+
let mut plot_name = Alphanumeric.sample_string(&mut rng(), 22);
300300
plot_name.push_str(".html");
301301
plot_name = format!("plotly_{}", plot_name);
302302
temp.push(plot_name);
@@ -354,13 +354,13 @@ impl Plot {
354354
pub fn to_inline_html(&self, plot_div_id: Option<&str>) -> String {
355355
let plot_div_id = match plot_div_id {
356356
Some(id) => id.to_string(),
357-
None => Alphanumeric.sample_string(&mut thread_rng(), 20),
357+
None => Alphanumeric.sample_string(&mut rng(), 20),
358358
};
359359
self.render_inline(&plot_div_id)
360360
}
361361

362362
fn to_jupyter_notebook_html(&self) -> String {
363-
let plot_div_id = Alphanumeric.sample_string(&mut thread_rng(), 20);
363+
let plot_div_id = Alphanumeric.sample_string(&mut rng(), 20);
364364

365365
let tmpl = JupyterNotebookPlotTemplate {
366366
plot: self,

plotly/src/traces/histogram.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ where
220220
///
221221
/// fn ndarray_to_traces() {
222222
/// let n: usize = 1_250;
223-
/// let mut rng = rand::thread_rng();
223+
/// let mut rng = rand::rng();
224224
/// let t: Array<f64, Ix1> = Array::range(0., 10., 10. / n as f64);
225225
/// let mut ys: Array<f64, Ix2> = Array::zeros((n, 4));
226226
/// let mut count = 0.;

0 commit comments

Comments
 (0)