[−][src]Struct droprate::FairlyRandomTable
FairlyRandomTable
aims to create results which a human might create when
asked to create a random sequence from a weighted table. It is human nature
to generate a more evenly-distributed list of random values because we are
aware of the the history of options chosen.
Calling this a "random" table strains the definition -- it is certainly going to give you "mixed up" results, but ultimately they will be far more predictable. That said, they will also feel much more "fair" to users who experience them.
For example: Given a result with a 1-in-10 odds ratio, there is still a 30% chance that you won't get that result within 10 trials. There is a 12% chance that you won't even see the result within 20 trials. This is where players start to complain that the devs hate them.
With FairlyRandomTable
, every trial which doesn't give a certain result
increases the probability of that result on the next trial (proportional to
its initial probability) until it is selected, which decreases its probability
dramatically (however it's not impossible to get multiple results in a row --
in fact, allowing for multiple results in a row of even unlikely options is
a design goal; you just won't seem them as frequently).
Methods
impl<T: Eq + Hash + Clone> FairlyRandomTable<T>
[src]
pub fn new() -> FairlyRandomTable<T>
[src]
Create a new instance of FairlyRandomTable
with no options.
pub fn from_map(in_table: HashMap<T, f64>) -> FairlyRandomTable<T>
[src]
Create a new FairlyRandomTable
from a HashMap
.
Examples
use droprate::{FairlyRandomTable, ProbabilityTable}; use std::collections::HashMap; let map: HashMap<&'static str, f64> = [("A", 1f64), ("B", 1f64), ("C", 3f64)] .iter().cloned().collect(); let mut table = FairlyRandomTable::<&'static str>::from_map(map); assert_eq!(3, table.count());
use droprate::{FairlyRandomTable, ProbabilityTable}; use std::collections::HashMap; let mut map = HashMap::new(); map.insert("A", 1f64); map.insert("B", 1f64); map.insert("C", 3f64); let mut table = FairlyRandomTable::<&'static str>::from_map(map); assert_eq!(3, table.count());
pub fn pure_random(&self) -> Result<T, String>
[src]
Run a trial from this as though it were a RandomTable
. The table's
results memory will not be affected, and as such future results from
calling random()
will not account for this trial.
Trait Implementations
impl<T: Eq + Hash + Clone> ProbabilityTable<T> for FairlyRandomTable<T>
[src]
Auto Trait Implementations
impl<T> Sync for FairlyRandomTable<T> where
T: Sync,
T: Sync,
impl<T> Send for FairlyRandomTable<T> where
T: Send,
T: Send,
impl<T> Unpin for FairlyRandomTable<T> where
T: Unpin,
T: Unpin,
impl<T> RefUnwindSafe for FairlyRandomTable<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> UnwindSafe for FairlyRandomTable<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,