22 use,
intrinsic :: iso_fortran_env
41 integer(int64),
parameter,
public :: &
42 splitmix64_123 = int(z
'B4DC9BD462DE412B', int64), &
56 integer(int64),
intent(inout) :: x
61 x = ieor(x, shiftl(x, 13))
62 x = ieor(x, shiftr(x, 7))
63 x = ieor(x, shiftl(x, 17))
77 integer(int64),
intent(in) :: x
79 real(real64),
parameter :: two_pow_minus_53 = real(z
'3CA0000000000000', real64)
81 d = real(shiftr(x, 11), real64) * two_pow_minus_53
87 integer(int64),
intent(inout) :: iseed
88 real(real64),
intent(out) :: rnd
99 integer(int64),
intent(inout) :: iseed
100 integer,
intent(in) :: nn
101 real(real64),
intent(inout) :: rnd(:)
105 push_sub(quickrnd_array)
111 pop_sub(quickrnd_array)
118 integer(int64),
intent(inout) :: iseed
119 integer,
intent(in) :: nn
120 complex(real64),
intent(inout) :: rnd(:)
122 real(real64),
parameter :: inv_sqrt2 = 1.0_real64 /
sqrt(
m_two)
123 real(real64) :: re, im
126 push_sub(quickrnd_array)
131 rnd(ii) = cmplx(re, im, real64) * inv_sqrt2
134 pop_sub(quickrnd_array)
141 integer(int64),
intent(inout) :: iseed
142 integer(int64),
intent(in) :: n
144 integer(int64) :: discard
162 integer(int32),
intent(inout) :: x
164 x = ieor(x, ishft(x, 13_int32))
165 x = ieor(x, ishft(x, -17_int32))
166 x = ieor(x, ishft(x, 5_int32))
170 x = iand(x, z
'7FFFFFFF')
177 real(real64),
intent(in ) :: x_min, x_max
178 integer(int32),
intent(inout) :: seed
181 real(real64),
parameter :: max_value_xorshift_32 = 2147483647_real64
182 real(real64) :: scale
185 scale = real(seed, real64) / max_value_xorshift_32
186 rand = scale * (x_max - x_min) + x_min
210 real(real64),
intent(in ) :: weight(:)
211 integer(int32),
intent(out) :: reservoir(:)
212 integer(int32),
intent(in ),
optional :: seed_value
216 real(real64) :: u_i, u_i2
218 real(real64),
allocatable :: key(:)
220 integer(int32) :: min_key_index, i, seed_size
221 integer(int32),
allocatable :: seed(:)
222 real(real64) :: thres_w
226 real(real64),
parameter :: a = 1.e-10_real64
227 real(real64),
parameter :: b = 1._real64 - 1.e-10_real64
236 if (
present(seed_value))
then
237 safe_allocate_source(seed(1:1), seed_value)
240 call random_seed(size=seed_size)
241 safe_allocate(seed(1:seed_size))
242 call random_seed(get=seed)
247 safe_allocate(key(1:m))
252 key(i) = u_i ** (1._real64 / weight(i))
253 if (key(i) < key(min_key_index)) min_key_index = i
257 xw =
log(u_i) /
log(key(min_key_index))
263 if (xw <= 0._real64)
then
264 reservoir(min_key_index) = i
265 thres_w = key(min_key_index)**weight(i)
268 key(min_key_index) = u_i2 ** (1._real64 / weight(i))
269 min_key_index = minloc(key, dim=1)
271 xw =
log(u_i) /
log(key(min_key_index))
276 safe_deallocate_a(key)
277 safe_deallocate_a(seed)
double log(double __x) __attribute__((__nothrow__
double sqrt(double __x) __attribute__((__nothrow__
real(real64), parameter, public m_two
subroutine dquickrnd_array(iseed, nn, rnd)
integer(int64), parameter, public splitmix64_321
subroutine, public reservoir_sampling_aexpj(weight, reservoir, seed_value)
Algorithm "A-ExpJ" weighted reservoir sampling without replacement.
subroutine, public shiftseed(iseed, n)
real(real64) function random_real_in_range(x_min, x_max, seed)
Generate a random real64 in the range .
real(real64) function, private to_double(x)
Generating uniform doubles in the unit interval.
subroutine xorshift_rnd_32_biased(x)
subroutine dquickrnd_single(iseed, rnd)
subroutine zquickrnd_array(iseed, nn, rnd)
integer(int64) function, private xorshift64(x)
xorshift64 pseudorandom number generator