Octopus
quickrnd_oct_m Module Reference

Data Types

interface  quickrnd
 

Functions/Subroutines

integer(int64) function, private xorshift64 (x)
 xorshift64 pseudorandom number generator More...
 
real(real64) function, private to_double (x)
 Generating uniform doubles in the unit interval. More...
 
subroutine dquickrnd_single (iseed, rnd)
 
subroutine dquickrnd_array (iseed, nn, rnd)
 
subroutine zquickrnd_array (iseed, nn, rnd)
 
subroutine, public shiftseed (iseed, n)
 
subroutine xorshift_rnd_32_biased (x)
 
real(real64) function random_real_in_range (x_min, x_max, seed)
 Generate a random real64 in the range \( [x_{min}, x_{max}] \). More...
 
subroutine, public reservoir_sampling_aexpj (weight, reservoir, seed_value)
 Algorithm "A-ExpJ" weighted reservoir sampling without replacement. More...
 

Variables

integer(int64), parameter, public splitmix64_123 = int(Z'B4DC9BD462DE412B', int64)
 
integer(int64), parameter, public splitmix64_321 = int(Z'E95F1C4EFCF85DEE', int64)
 

Function/Subroutine Documentation

◆ xorshift64()

integer(int64) function, private quickrnd_oct_m::xorshift64 ( integer(int64), intent(inout)  x)
private

xorshift64 pseudorandom number generator

Marsaglia, G. (2003). Xorshift RNGs. Journal of Statistical Software, 8(14). https:

Parameters
[in,out]xPRNG state
Returns
next random number in the sequence

Definition at line 148 of file quickrnd.F90.

◆ to_double()

real(real64) function, private quickrnd_oct_m::to_double ( integer(int64), intent(in)  x)
private

Generating uniform doubles in the unit interval.

We consider x to be an unsigned 64-bit integer which can represent the range \([0,2^{64})\). First we shift x right by 11 places which puts it in the range \([0,2^{53})\). Then we convert it to a double and multiply by \(2^{-53}\) which puts the result in the range \([0,1)\).

https:

Parameters
[in]x64-bit integer
Returns
double precision floating point number in the interval [0,1)

Definition at line 169 of file quickrnd.F90.

◆ dquickrnd_single()

subroutine quickrnd_oct_m::dquickrnd_single ( integer(int64), intent(inout)  iseed,
real(real64), intent(out)  rnd 
)

Definition at line 179 of file quickrnd.F90.

◆ dquickrnd_array()

subroutine quickrnd_oct_m::dquickrnd_array ( integer(int64), intent(inout)  iseed,
integer, intent(in)  nn,
real(real64), dimension(:), intent(inout)  rnd 
)

Definition at line 191 of file quickrnd.F90.

◆ zquickrnd_array()

subroutine quickrnd_oct_m::zquickrnd_array ( integer(int64), intent(inout)  iseed,
integer, intent(in)  nn,
complex(real64), dimension(:), intent(inout)  rnd 
)

Definition at line 210 of file quickrnd.F90.

◆ shiftseed()

subroutine, public quickrnd_oct_m::shiftseed ( integer(int64), intent(inout)  iseed,
integer(int64), intent(in)  n 
)

Definition at line 233 of file quickrnd.F90.

◆ xorshift_rnd_32_biased()

subroutine quickrnd_oct_m::xorshift_rnd_32_biased ( integer(int32), intent(inout)  x)

Definition at line 254 of file quickrnd.F90.

◆ random_real_in_range()

real(real64) function quickrnd_oct_m::random_real_in_range ( real(real64), intent(in)  x_min,
real(real64), intent(in)  x_max,
integer(int32), intent(inout)  seed 
)

Generate a random real64 in the range \( [x_{min}, x_{max}] \).

Definition at line 269 of file quickrnd.F90.

◆ reservoir_sampling_aexpj()

subroutine, public quickrnd_oct_m::reservoir_sampling_aexpj ( real(real64), dimension(:), intent(in)  weight,
integer(int32), dimension(:), intent(out)  reservoir,
integer(int32), intent(in), optional  seed_value 
)

Algorithm "A-ExpJ" weighted reservoir sampling without replacement.

Randomly sample a reservoir of \(m\) values from a population of \([1, n]\) integers, with associated weights. Algorithm A-ExpJ is described in Weighted random sampling with a reservoir and the [wikipedia page](https: as \(mlog(m/n)\).

Input Weights

The key function, \( u_i^{1/w_i} \), blows up for small weights, \(\{w_i\}\). It is the caller''s responsibility to ensure that correctly scaled, finite weights \(\ge 1\) are supplied to the routine. Rescaling could be avoided by implementing a different key function, however one would need to consistently modify the jump function \(X_w\).

Return Value

Rather than returning a reservoir of \(m\) values, \({V}\), this implementation returns the corresponding indices of these values. The caller can use these indices to retrieve the corresponding values like selected_values = values(reservoir).

Parameters
[in]weightWeights for the population
[out]reservoirm randomly-sampled indices from the population
[in]seed_valueInitial seed value for PRNG

Definition at line 302 of file quickrnd.F90.

Variable Documentation

◆ splitmix64_123

integer(int64), parameter, public quickrnd_oct_m::splitmix64_123 = int(Z'B4DC9BD462DE412B', int64)

Definition at line 134 of file quickrnd.F90.

◆ splitmix64_321

integer(int64), parameter, public quickrnd_oct_m::splitmix64_321 = int(Z'E95F1C4EFCF85DEE', int64)

Definition at line 134 of file quickrnd.F90.