rand: Switch field privacy as necessary
This commit is contained in:
parent
14587f88ca
commit
02cf3751df
10 changed files with 45 additions and 43 deletions
|
@ -66,7 +66,7 @@ impl Rand for Exp1 {
|
|||
/// ```
|
||||
pub struct Exp {
|
||||
/// `lambda` stored as `1/lambda`, since this is what we scale by.
|
||||
priv lambda_inverse: f64
|
||||
lambda_inverse: f64
|
||||
}
|
||||
|
||||
impl Exp {
|
||||
|
|
|
@ -236,11 +236,11 @@ impl IndependentSample<f64> for ChiSquared {
|
|||
/// println!("{} is from an F(2, 32) distribution", v)
|
||||
/// ```
|
||||
pub struct FisherF {
|
||||
priv numer: ChiSquared,
|
||||
priv denom: ChiSquared,
|
||||
numer: ChiSquared,
|
||||
denom: ChiSquared,
|
||||
// denom_dof / numer_dof so that this can just be a straight
|
||||
// multiplication, rather than a division.
|
||||
priv dof_ratio: f64,
|
||||
dof_ratio: f64,
|
||||
}
|
||||
|
||||
impl FisherF {
|
||||
|
@ -279,8 +279,8 @@ impl IndependentSample<f64> for FisherF {
|
|||
/// println!("{} is from a t(11) distribution", v)
|
||||
/// ```
|
||||
pub struct StudentT {
|
||||
priv chi: ChiSquared,
|
||||
priv dof: f64
|
||||
chi: ChiSquared,
|
||||
dof: f64
|
||||
}
|
||||
|
||||
impl StudentT {
|
||||
|
|
|
@ -71,9 +71,9 @@ impl<Sup: Rand> IndependentSample<Sup> for RandSample<Sup> {
|
|||
/// A value with a particular weight for use with `WeightedChoice`.
|
||||
pub struct Weighted<T> {
|
||||
/// The numerical weight of this item
|
||||
weight: uint,
|
||||
pub weight: uint,
|
||||
/// The actual item which is being weighted
|
||||
item: T,
|
||||
pub item: T,
|
||||
}
|
||||
|
||||
/// A distribution that selects from a finite collection of weighted items.
|
||||
|
@ -101,8 +101,8 @@ pub struct Weighted<T> {
|
|||
/// }
|
||||
/// ```
|
||||
pub struct WeightedChoice<T> {
|
||||
priv items: ~[Weighted<T>],
|
||||
priv weight_range: Range<uint>
|
||||
pub items: ~[Weighted<T>],
|
||||
pub weight_range: Range<uint>
|
||||
}
|
||||
|
||||
impl<T: Clone> WeightedChoice<T> {
|
||||
|
|
|
@ -82,8 +82,8 @@ impl Rand for StandardNormal {
|
|||
/// println!("{} is from a N(2, 9) distribution", v)
|
||||
/// ```
|
||||
pub struct Normal {
|
||||
priv mean: f64,
|
||||
priv std_dev: f64
|
||||
mean: f64,
|
||||
std_dev: f64,
|
||||
}
|
||||
|
||||
impl Normal {
|
||||
|
@ -124,7 +124,7 @@ impl IndependentSample<f64> for Normal {
|
|||
/// println!("{} is from an ln N(2, 9) distribution", v)
|
||||
/// ```
|
||||
pub struct LogNormal {
|
||||
priv norm: Normal
|
||||
norm: Normal
|
||||
}
|
||||
|
||||
impl LogNormal {
|
||||
|
|
|
@ -46,9 +46,9 @@ use distributions::{Sample, IndependentSample};
|
|||
/// }
|
||||
/// ```
|
||||
pub struct Range<X> {
|
||||
priv low: X,
|
||||
priv range: X,
|
||||
priv accept_zone: X
|
||||
low: X,
|
||||
range: X,
|
||||
accept_zone: X
|
||||
}
|
||||
|
||||
impl<X: SampleRange + Ord> Range<X> {
|
||||
|
|
|
@ -28,12 +28,12 @@ static RAND_SIZE: u32 = 1 << RAND_SIZE_LEN;
|
|||
/// [1]: Bob Jenkins, [*ISAAC: A fast cryptographic random number
|
||||
/// generator*](http://www.burtleburtle.net/bob/rand/isaacafa.html)
|
||||
pub struct IsaacRng {
|
||||
priv cnt: u32,
|
||||
priv rsl: [u32, .. RAND_SIZE],
|
||||
priv mem: [u32, .. RAND_SIZE],
|
||||
priv a: u32,
|
||||
priv b: u32,
|
||||
priv c: u32
|
||||
cnt: u32,
|
||||
rsl: [u32, .. RAND_SIZE],
|
||||
mem: [u32, .. RAND_SIZE],
|
||||
a: u32,
|
||||
b: u32,
|
||||
c: u32
|
||||
}
|
||||
static EMPTY: IsaacRng = IsaacRng {
|
||||
cnt: 0,
|
||||
|
@ -231,12 +231,12 @@ static RAND_SIZE_64: uint = 1 << RAND_SIZE_64_LEN;
|
|||
/// [1]: Bob Jenkins, [*ISAAC: A fast cryptographic random number
|
||||
/// generator*](http://www.burtleburtle.net/bob/rand/isaacafa.html)
|
||||
pub struct Isaac64Rng {
|
||||
priv cnt: uint,
|
||||
priv rsl: [u64, .. RAND_SIZE_64],
|
||||
priv mem: [u64, .. RAND_SIZE_64],
|
||||
priv a: u64,
|
||||
priv b: u64,
|
||||
priv c: u64,
|
||||
cnt: uint,
|
||||
rsl: [u64, .. RAND_SIZE_64],
|
||||
mem: [u64, .. RAND_SIZE_64],
|
||||
a: u64,
|
||||
b: u64,
|
||||
c: u64,
|
||||
}
|
||||
|
||||
static EMPTY_64: Isaac64Rng = Isaac64Rng {
|
||||
|
|
|
@ -72,6 +72,8 @@ println!("{:?}", tuple_ptr)
|
|||
|
||||
#![feature(macro_rules, managed_boxes, phase)]
|
||||
|
||||
#![allow(visible_private_types)] // NOTE: remove after a stage0 snap
|
||||
|
||||
#[cfg(test)]
|
||||
#[phase(syntax, link)] extern crate log;
|
||||
|
||||
|
@ -407,12 +409,12 @@ pub fn rng() -> StdRng {
|
|||
/// The standard RNG. This is designed to be efficient on the current
|
||||
/// platform.
|
||||
#[cfg(not(target_word_size="64"))]
|
||||
pub struct StdRng { priv rng: IsaacRng }
|
||||
pub struct StdRng { rng: IsaacRng }
|
||||
|
||||
/// The standard RNG. This is designed to be efficient on the current
|
||||
/// platform.
|
||||
#[cfg(target_word_size="64")]
|
||||
pub struct StdRng { priv rng: Isaac64Rng }
|
||||
pub struct StdRng { rng: Isaac64Rng }
|
||||
|
||||
impl StdRng {
|
||||
/// Create a randomly seeded instance of `StdRng`.
|
||||
|
@ -489,10 +491,10 @@ pub fn weak_rng() -> XorShiftRng {
|
|||
/// RNGs"](http://www.jstatsoft.org/v08/i14/paper). *Journal of
|
||||
/// Statistical Software*. Vol. 8 (Issue 14).
|
||||
pub struct XorShiftRng {
|
||||
priv x: u32,
|
||||
priv y: u32,
|
||||
priv z: u32,
|
||||
priv w: u32,
|
||||
x: u32,
|
||||
y: u32,
|
||||
z: u32,
|
||||
w: u32,
|
||||
}
|
||||
|
||||
impl Rng for XorShiftRng {
|
||||
|
@ -573,8 +575,8 @@ pub struct TaskRng {
|
|||
// The use of unsafe code here is OK if the invariants above are
|
||||
// satisfied; and it allows us to avoid (unnecessarily) using a
|
||||
// GC'd or RC'd pointer.
|
||||
priv rng: *mut TaskRngInner,
|
||||
priv marker: marker::NoSend,
|
||||
rng: *mut TaskRngInner,
|
||||
marker: marker::NoSend,
|
||||
}
|
||||
|
||||
// used to make space in TLS for a random number generator
|
||||
|
|
|
@ -30,7 +30,7 @@ mod imp {
|
|||
/// This does not block.
|
||||
#[cfg(unix)]
|
||||
pub struct OSRng {
|
||||
priv inner: ReaderRng<File>
|
||||
inner: ReaderRng<File>
|
||||
}
|
||||
|
||||
impl OSRng {
|
||||
|
@ -77,7 +77,7 @@ mod imp {
|
|||
///
|
||||
/// This does not block.
|
||||
pub struct OSRng {
|
||||
priv hcryptprov: HCRYPTPROV
|
||||
hcryptprov: HCRYPTPROV
|
||||
}
|
||||
|
||||
static PROV_RSA_FULL: DWORD = 1;
|
||||
|
|
|
@ -27,7 +27,7 @@ use Rng;
|
|||
/// println!("{:x}", rng.gen::<uint>());
|
||||
/// ```
|
||||
pub struct ReaderRng<R> {
|
||||
priv reader: R
|
||||
reader: R
|
||||
}
|
||||
|
||||
impl<R: Reader> ReaderRng<R> {
|
||||
|
|
|
@ -21,11 +21,11 @@ static DEFAULT_GENERATION_THRESHOLD: uint = 32 * 1024;
|
|||
/// A wrapper around any RNG which reseeds the underlying RNG after it
|
||||
/// has generated a certain number of random bytes.
|
||||
pub struct ReseedingRng<R, Rsdr> {
|
||||
priv rng: R,
|
||||
priv generation_threshold: uint,
|
||||
priv bytes_generated: uint,
|
||||
rng: R,
|
||||
generation_threshold: uint,
|
||||
bytes_generated: uint,
|
||||
/// Controls the behaviour when reseeding the RNG.
|
||||
reseeder: Rsdr
|
||||
pub reseeder: Rsdr,
|
||||
}
|
||||
|
||||
impl<R: Rng, Rsdr: Reseeder<R>> ReseedingRng<R, Rsdr> {
|
||||
|
|
Loading…
Add table
Reference in a new issue