1 // Copyright 2018 Developers of the Rand project.
3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4 // https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5 // <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6 // option. This file may not be copied, modified, or distributed
7 // except according to those terms.
9 //! The Weibull distribution.
12 use crate::distributions
::{Distribution, OpenClosed01}
;
15 /// Samples floating-point numbers according to the Weibull distribution
16 #[deprecated(since = "0.7.0", note = "moved to rand_distr crate")]
17 #[derive(Clone, Copy, Debug)]
24 /// Construct a new `Weibull` distribution with given `scale` and `shape`.
28 /// `scale` and `shape` have to be non-zero and positive.
29 pub fn new(scale
: f64, shape
: f64) -> Weibull
{
30 assert
!((scale
> 0.) & (shape
> 0.));
32 inv_shape
: 1. / shape
,
38 impl Distribution
<f64> for Weibull
{
39 fn sample
<R
: Rng
+ ?Sized
>(&self, rng
: &mut R
) -> f64 {
40 let x
: f64 = rng
.sample(OpenClosed01
);
41 self.scale
* (-x
.ln()).powf(self.inv_shape
)
48 use crate::distributions
::Distribution
;
60 let d
= Weibull
::new(scale
, shape
);
61 let mut rng
= crate::test
::rng(1);
63 let r
= d
.sample(&mut rng
);