Random

Struct Random 

Source
pub struct Random { /* private fields */ }
Expand description

A random.org api client.

Implementations§

Source§

impl Random

Source

pub fn new<S: Into<String>>(api_key: S) -> Random

Creates new random.org client.

§Usage
extern crate randomorg;

fn main() {
    use randomorg::Random;
    let r = Random::new("API KEY HERE");
}
Source

pub fn request_integers(&self) -> RequestIntegers<'_>

Create a request object for generating random integers

§Usage
extern crate randomorg;

fn main() {
    use randomorg::Random;
    let r = Random::new("API KEY HERE");
    let random_data = r.request_integers().min(0).max(100).limit(5).collect::<Vec<i32>>();
    println!("Random integers: {:?}", random_data);
}
Source

pub fn request_decimal_fractions(&self) -> RequestDecimalFractions<'_>

Create a request object for generating random decimal fractions

§Usage
extern crate randomorg;

fn main() {
    use randomorg::Random;
    let r = Random::new("API KEY HERE");
    let random_data = r.request_decimal_fractions().limit(5)
                                                   .decimal_places(4)
                                                   .collect::<Vec<f32>>();
    println!("Random decimal fractions: {:?}", random_data);
}
Source

pub fn request_gaussians(&self) -> RequestGaussians<'_>

Create a request object for generating random gaussians

§Usage
extern crate randomorg;

fn main() {
    use randomorg::Random;
    let r = Random::new("API KEY HERE");
    let random_data = r.request_gaussians().limit(5)
                                           .collect::<Vec<f32>>();
    println!("Random gaussians: {:?}", random_data);
}
Source

pub fn request_strings(&self) -> RequestStrings<'_>

Create a request object for generating random strings

§Usage
extern crate randomorg;

fn main() {
    use randomorg::Random;
    let r = Random::new("API KEY HERE");
    let random_data = r.request_strings().limit(5)
                                         .collect::<Vec<String>>();
    println!("Random strings: {:?}", random_data);
}
Source

pub fn request_uuids(&self) -> RequestUUIDs<'_>

Create a request object for generating random UUIDs

§Usage
extern crate randomorg;

fn main() {
    use randomorg::Random;
    let r = Random::new("API KEY HERE");
    let random_data = r.request_uuids().limit(5)
                                       .collect::<Vec<String>>();
    println!("Random strings: {:?}", random_data);
}
Source

pub fn request_blobs(&self) -> RequestBlobs<'_>

Create a request object for generating random blobs

§Usage
extern crate randomorg;

fn main() {
    use randomorg::Random;
    let r = Random::new("API KEY HERE");
    let random_data = r.request_blobs().limit(5)
                                       .collect::<Vec<String>>();
    println!("Random strings: {:?}", random_data);
}
Source

pub fn generate_integers( &self, min: i32, max: i32, limit: u16, replacement: bool, ) -> Result<Response<GenerateIntegersResult>>

This method generates true random integers within a user-defined range.

§Usage
extern crate randomorg;

fn main() {
    use randomorg::Random;
    let r = Random::new("API KEY HERE");
    println!("Result: {:?}", r.generate_integers(-100, 100, 15, true));
}
§Constraints
  • min must be within [-1e9; 1e9] range
  • max must be within [-1e9; 1e9] range
  • limit must be within [1; 1e4] range
Source

pub fn generate_decimal_fractions( &self, limit: u16, decimal_places: u8, ) -> Result<Response<GenerateDecimalFractionsResult>>

This method generates true random decimal fractions from a uniform distribution across the [0,1] interval with a user-defined number of decimal places.

§Usage
extern crate randomorg;

fn main() {
    use randomorg::Random;
    let r = Random::new("API KEY HERE");
    println!("Result: {:?}", r.generate_decimal_fractions(10, 8));
}
§Constraints
  • limit must be within [1; 1e4] range
  • decimal_places must be within [1; 20] range
Source

pub fn generate_gaussians( &self, limit: u16, mean: i32, standard_deviation: i32, significant_digits: u8, ) -> Result<Response<GenerateGaussiansResult>>

This method generates true random numbers from a Gaussian distribution (also known as a normal distribution). The form uses a Box-Muller Transform to generate the Gaussian distribution from uniformly distributed numbers.

§Usage
extern crate randomorg;

fn main() {
    use randomorg::Random;
    let r = Random::new("API KEY HERE");
    println!("Result: {:?}", r.generate_gaussians(2000, 1100, 100, 4));
}
§Constraints
  • limit must be within [1; 1e4] range
  • mean must be within [-1e6; 1e6] range
  • standard_deviation must be within [-1e6; 1e6] range
  • significant_digits must be within [2; 20] range
Source

pub fn generate_strings( &self, limit: u16, length: u8, characters: AllowedCharacters, ) -> Result<Response<GenerateStringsResult>>

This method generates true random strings.

§Usage
extern crate randomorg;

fn main() {
    use randomorg::{ Random, AllowedCharacters };
    use std::collections::BTreeSet;
    let chars = "abcde".chars().collect::<BTreeSet<char>>();
    let r = Random::new("API KEY HERE");
    println!("Result: {:?}", r.generate_strings(5, 10, AllowedCharacters(chars)));
}
§Constraints
  • limit must be within [1; 1e4] range
  • length must be within [1; 20] range
  • characters must contain maximum 80 characters.
Source

pub fn generate_uuids( &self, limit: u16, ) -> Result<Response<GenerateUUIDsResult>>

This method generates version 4 true random Universally Unique IDentifiers (UUIDs) in accordance with section 4.4 of RFC 4122.

§Usage
extern crate randomorg;

fn main() {
    use randomorg::Random;
    let r = Random::new("API KEY HERE");
    println!("Result: {:?}", r.generate_uuids(5));
}
§Constraints
  • limit must be within [1; 1e3] range
Source

pub fn generate_blobs( &self, limit: u16, size: u32, ) -> Result<Response<GenerateBlobsResult>>

This method generates Binary Large OBjects (BLOBs) containing true random data.

§Usage
extern crate randomorg;

fn main() {
    use randomorg::Random;
    let r = Random::new("API KEY HERE");
    println!("Result: {:?}", r.generate_blobs(5, 16));
}
§Constraints
  • limit must be within [1; 100] range
  • size must be within [1, 1048576] range
Source

pub fn get_usage(&self) -> Result<Response<GetUsageResult>>

Returns information related to the usage of a given API key.

§Usage
extern crate randomorg;

fn main() {
    use randomorg::Random;
    let r = Random::new("API KEY HERE");
    println!("Result: {:?}", r.get_usage());
}

Trait Implementations§

Source§

impl Clone for Random

Source§

fn clone(&self) -> Random

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Random

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Random

§

impl !RefUnwindSafe for Random

§

impl Send for Random

§

impl Sync for Random

§

impl Unpin for Random

§

impl !UnwindSafe for Random

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,