@@ -34,6 +34,10 @@ module stdlib_stats_distribution_normal
3434 #:for k1, t1 in RC_KINDS_TYPES
3535 module procedure rvs_norm_array_${t1[0]}$${k1}$ !3 dummy variables
3636 #:endfor
37+
38+ #:for k1, t1 in RC_KINDS_TYPES
39+ module procedure rvs_norm_array_default_${t1[0]}$${k1}$ !2 dummy variables (mold, array_size)
40+ #:endfor
3741 end interface rvs_normal
3842
3943 interface pdf_normal
@@ -238,6 +242,82 @@ contains
238242
239243 #:endfor
240244
245+ #:for k1, t1 in REAL_KINDS_TYPES
246+ impure function rvs_norm_array_default_${t1[0]}$${k1}$ (mold, array_size) result(res)
247+ !
248+ ! Standard normal array random variate with default loc=0, scale=1
249+ ! The mold argument is used only to determine the type and is not referenced
250+ !
251+ ${t1}$, intent(in) :: mold
252+ integer, intent(in) :: array_size
253+ ${t1}$ :: res(array_size)
254+ ${t1}$, parameter :: r = 3.442619855899_${k1}$, rr = 1.0_${k1}$/r
255+ ${t1}$ :: x, y, re
256+ integer :: hz, iz, i
257+
258+ if (.not. zig_norm_initialized) call zigset
259+
260+ do i = 1, array_size
261+ iz = 0
262+ hz = dist_rand(1_int32)
263+ iz = iand(hz, 127)
264+ if (abs(hz) < kn(iz)) then
265+ re = hz*wn(iz)
266+ else
267+ L1: do
268+ L2: if (iz == 0) then
269+ do
270+ x = -log(uni(1.0_${k1}$))*rr
271+ y = -log(uni(1.0_${k1}$))
272+ if (y + y >= x*x) exit
273+ end do
274+ re = r + x
275+ if (hz <= 0) re = -re
276+ exit L1
277+ end if L2
278+ x = hz*wn(iz)
279+ if (fn(iz) + uni(1.0_${k1}$)*(fn(iz - 1) - fn(iz)) < &
280+ exp(-HALF*x*x)) then
281+ re = x
282+ exit L1
283+ end if
284+
285+ hz = dist_rand(1_int32)
286+ iz = iand(hz, 127)
287+ if (abs(hz) < kn(iz)) then
288+ re = hz*wn(iz)
289+ exit L1
290+ end if
291+ end do L1
292+ end if
293+ res(i) = re ! Default: loc=0, scale=1, so re*1 + 0 = re
294+ end do
295+ end function rvs_norm_array_default_${t1[0]}$${k1}$
296+
297+ #:endfor
298+
299+ #:for k1, t1 in CMPLX_KINDS_TYPES
300+ impure function rvs_norm_array_default_${t1[0]}$${k1}$ (mold, array_size) result(res)
301+ !
302+ ! Standard normal complex array random variate with default loc=0, scale=1
303+ ! The mold argument is used only to determine the type and is not referenced
304+ !
305+ ${t1}$, intent(in) :: mold
306+ integer, intent(in) :: array_size
307+ integer :: i
308+ ${t1}$ :: res(array_size)
309+ real(${k1}$) :: tr, ti
310+
311+ do i = 1, array_size
312+ tr = rvs_norm_0_r${k1}$ ()
313+ ti = rvs_norm_0_r${k1}$ ()
314+ res(i) = cmplx(tr, ti, kind=${k1}$)
315+ end do
316+
317+ end function rvs_norm_array_default_${t1[0]}$${k1}$
318+
319+ #:endfor
320+
241321 #:for k1, t1 in CMPLX_KINDS_TYPES
242322 impure function rvs_norm_array_${t1[0]}$${k1}$ (loc, scale, array_size) result(res)
243323 ${t1}$, intent(in) :: loc, scale
0 commit comments