Sample SNPs
Fast ordered sampling of rows from large text or binary files. Special cases for DNA variant files (.bed, VCF, HapMap, etc).
Public Member Functions | List of all members
sampFiles::RanDraw Class Reference

Random number generating class. More...

#include <random.hpp>

Public Member Functions

 RanDraw ()
 Default constructor. More...
 
 ~RanDraw ()
 Destructor.
 
 RanDraw (const RanDraw &old)=default
 Copy constructor. More...
 
 RanDraw (RanDraw &&old)=default
 Move constructor. More...
 
RanDrawoperator= (const RanDraw &old)=default
 Copy assignment. More...
 
RanDrawoperator= (RanDraw &&old)=default
 Move assignment. More...
 
volatile uint64_t ranInt ()
 Generate random integer. More...
 
volatile double runif ()
 Generate a uniform deviate. More...
 
volatile double runifnz ()
 Generate a non-zero uniform deviate. More...
 
volatile uint64_t vitterA (const double &n, const double &N)
 Sample from Vitter's distribution, method A. More...
 
volatile uint64_t vitter (const double &n, const double &N)
 Sample from Vitter's distribution, method D. More...
 

Detailed Description

Random number generating class.

Generates (pseudo-)random deviates from a number of distributions. If hardware random numbers are supported, uses them. Otherwise, falls back to 64-bit MT19937 ("Mersenne Twister").

Constructor & Destructor Documentation

◆ RanDraw() [1/3]

RanDraw::RanDraw ( )

Default constructor.

Checks if the processor provides hardware random number support. Seeds the Mersenne Twister if not. Throws "CPU_unsupported" string object if the CPU is not AMD or Intel.

◆ RanDraw() [2/3]

sampFiles::RanDraw::RanDraw ( const RanDraw old)
default

Copy constructor.

Parameters
[in]oldpbject to be copied

◆ RanDraw() [3/3]

sampFiles::RanDraw::RanDraw ( RanDraw &&  old)
default

Move constructor.

Parameters
[in]oldpbject to be moved

Member Function Documentation

◆ operator=() [1/2]

RanDraw& sampFiles::RanDraw::operator= ( const RanDraw old)
default

Copy assignment.

Parameters
[in]oldpbject to be copied

◆ operator=() [2/2]

RanDraw& sampFiles::RanDraw::operator= ( RanDraw &&  old)
default

Move assignment.

Parameters
[in]oldpbject to be moved

◆ ranInt()

volatile uint64_t sampFiles::RanDraw::ranInt ( )
inline

Generate random integer.

Returns
An unsigned random 64-bit integer

◆ runif()

volatile double sampFiles::RanDraw::runif ( )
inline

Generate a uniform deviate.

Returns
A double-precision value from the \( U[0,1]\) distribution

◆ runifnz()

volatile double RanDraw::runifnz ( )

Generate a non-zero uniform deviate.

Returns
A double-precision value from the \( U(0,1]\) distribution

◆ vitter()

volatile uint64_t RanDraw::vitter ( const double &  n,
const double &  N 
)

Sample from Vitter's distribution, method D.

Given the number of remaining records in a file \(N\) and the number of records \(n\) remaining to be selected, sample the number of records to skip over. This function implements Vitter's [2] [3] method D. It is useful for online one-pass sampling of records from a file. While the inputs are integer, we pass them in as double because that is more efficient for calculations.

Parameters
[in]nnumber of records remaining to be picked
[in]Nnumber of remaining records in the file
Returns
the number of records to skip

◆ vitterA()

volatile uint64_t RanDraw::vitterA ( const double &  n,
const double &  N 
)

Sample from Vitter's distribution, method A.

Given the number of remaining records in a file \(N\) and the number of records \(n\) remaining to be selected, sample the number of records to skip over. This function implements Vitter's [2] [3] method A. It is useful for online one-pass sampling of records from a file. While the inputs are integer, we pass them in as double because that is more efficient for calculations.

Parameters
[in]nnumber of records remaining to be picked
[in]Nnumber of remaining records in the file
Returns
the number of records to skip

The documentation for this class was generated from the following files: