Skip to content

Commit 0ee49ae

Browse files
committed
update code to work with rand=0.9 and rand_distr=0.5 crates
Signed-off-by: Andrei Gherghescu <8067229+andrei-ng@users.noreply.github.com>
1 parent 93cad56 commit 0ee49ae

File tree

14 files changed

+38
-37
lines changed

14 files changed

+38
-37
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/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ edition = "2021"
66

77
[dependencies]
88
ndarray = "0.16"
9-
rand = "0.8"
9+
rand = "0.9"
1010
plotly = { path = "../../plotly" }

examples/3d_charts/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use plotly::{
77
layout::{Axis, Camera, Layout, LayoutScene, Legend, Margin, ProjectionType},
88
Mesh3D, Plot, Scatter3D, Surface,
99
};
10+
1011
use rand::Rng;
1112

1213
// 3D Scatter Plots
@@ -218,8 +219,8 @@ fn colorscale_plot(show: bool) -> Plot {
218219
let _color: Vec<usize> = (0..z.len()).collect();
219220
let _color: Vec<u8> = (0..z.len()).map(|x| x as u8).collect();
220221
let _color: Vec<i16> = {
221-
let mut rng = rand::thread_rng();
222-
(0..z.len()).map(|_| rng.gen_range(0..100)).collect()
222+
let mut rng = rand::rng();
223+
(0..z.len()).map(|_| rng.random_range(0..100)).collect()
223224
};
224225

225226
let color_max = color.iter().fold(f64::MIN, |acc, x| acc.max(*x as f64));

examples/basic_charts/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ edition = "2021"
77
[dependencies]
88
ndarray = "0.16"
99
plotly = { path = "../../plotly" }
10-
rand = "0.8"
11-
rand_distr = "0.4"
10+
rand = "0.9"
11+
rand_distr = "0.5"

examples/basic_charts/src/main.rs

Lines changed: 7 additions & 3 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,8 +273,12 @@ 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();
277-
let r: Vec<f64> = Uniform::new(0., 1.).sample_iter(&mut rng).take(n).collect();
276+
let mut rng = rand::rng();
277+
let r: Vec<f64> = Uniform::new(0., 1.)
278+
.unwrap()
279+
.sample_iter(&mut rng)
280+
.take(n)
281+
.collect();
278282
let theta: Vec<f64> = Normal::new(0., 2. * std::f64::consts::PI)
279283
.unwrap()
280284
.sample_iter(&mut rng)

examples/customization/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ edition = "2021"
66

77
[dependencies]
88
build_html = "2.5.0"
9-
rand = "0.8"
9+
rand = "0.9"
1010
ndarray = "0.16"
1111
plotly = { path = "../../plotly" }

examples/customization/src/main.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,11 @@ fn write_html(html_data: &str) -> String {
121121
use std::env;
122122
use std::{fs::File, io::Write};
123123

124-
use rand::{
125-
distributions::{Alphanumeric, DistString},
126-
thread_rng,
127-
};
124+
use rand::distr::{Alphanumeric, SampleString};
128125

129126
// Set up the temp file with a unique filename.
130127
let mut temp = env::temp_dir();
131-
let mut plot_name = Alphanumeric.sample_string(&mut thread_rng(), 22);
128+
let mut plot_name = Alphanumeric.sample_string(&mut rand::rng(), 22);
132129
plot_name.push_str(".html");
133130
plot_name = format!("plotly_{}", plot_name);
134131
temp.push(plot_name);

examples/shapes/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ edition = "2021"
77
[dependencies]
88
ndarray = "0.16"
99
plotly = { path = "../../plotly" }
10-
rand = "0.8"
11-
rand_distr = "0.4"
10+
rand = "0.9"
11+
rand_distr = "0.5"

examples/shapes/src/main.rs

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

1514
// ANCHOR: filled_area_chart
@@ -433,7 +432,7 @@ fn circles_positioned_relative_to_the_axes(show: bool) -> Plot {
433432

434433
// ANCHOR: highlighting_clusters_of_scatter_points_with_circle_shapes
435434
fn highlighting_clusters_of_scatter_points_with_circle_shapes(show: bool) -> Plot {
436-
let mut rng = thread_rng();
435+
let mut rng = rand::rng();
437436
let x0 = Normal::new(2., 0.45)
438437
.unwrap()
439438
.sample_iter(&mut rng)

examples/statistical_charts/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ edition = "2021"
77
[dependencies]
88
ndarray = "0.16"
99
plotly = { path = "../../plotly" }
10-
rand = "0.8"
11-
rand_distr = "0.4"
10+
rand = "0.9"
11+
rand_distr = "0.5"

0 commit comments

Comments
 (0)