private function pcg32_next_below(gen, n, error) result(r)
Uniform integer in [0, n) from a PCG32 generator. Each attempt consumes
two 32-bit outputs, so the stream stays word aligned no matter how many
rejections occur.
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed
arrows point from an interface to procedures which implement that interface.
This could include the module procedures in a generic interface or the
implementation in a submodule of an interface in a parent module.
Where possible, edges connecting nodes are
given different colours to make them easier to distinguish in
large graphs.
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed
arrows point from an interface to procedures which implement that interface.
This could include the module procedures in a generic interface or the
implementation in a submodule of an interface in a parent module.
Where possible, edges connecting nodes are
given different colours to make them easier to distinguish in
large graphs.
Variables
Type
Visibility
Attributes
Name
Initial
integer(kind=int64),
private
::
bound
integer(kind=int64),
private
::
candidate
integer(kind=int64),
private
::
mask
Source Code
function pcg32_next_below(gen,n,error)result(r)!! Uniform integer in [0, n) from a PCG32 generator. Each attempt consumes!! two 32-bit outputs, so the stream stays word aligned no matter how many!! rejections occur.type(pcg32_t),intent(inout)::geninteger(default_int),intent(in)::ntype(error_t),intent(inout),optional::errorinteger(default_int)::rinteger(int64)::bound,mask,candidater=0_default_intif(n<=0_default_int)then if(present(error))then call error%set(ERROR_VALIDATION,"pic_rng: next_below requires n > 0")end if return end if if(n==1_default_int)returnbound=int(n,int64)mask=rejection_mask(bound)docandidate=iand(gen%next_u64(),mask)if(candidate<bound)exit end dor=int(candidate,default_int)end function pcg32_next_below