215
215
"""
216
216
_cumulative(d::UnivariateFinite)
217
217
218
+ **Private method.**
219
+
218
220
Return the cumulative probability vector `C` for the distribution `d`,
219
221
using only classes in the support of `d`, ordered according to the
220
222
categorical elements used at instantiation of `d`. Used only to
@@ -238,13 +240,15 @@ end
238
240
"""
239
241
_rand(rng, p_cumulative, R)
240
242
243
+ **Private method.**
244
+
241
245
Randomly sample the distribution with discrete support `R(1):R(n)`
242
246
which has cumulative probability vector `p_cumulative` (see
243
247
[`_cummulative`](@ref)).
244
248
245
249
"""
246
250
function _rand (rng, p_cumulative, R)
247
- real_sample = rand (rng)* p_cumulative[end ]
251
+ real_sample = Base . rand (rng)* p_cumulative[end ]
248
252
K = R (length (p_cumulative))
249
253
index = K
250
254
for i in R (2 ): R (K)
@@ -261,10 +265,11 @@ function Base.rand(rng::AbstractRNG,
261
265
p_cumulative = _cumulative (d)
262
266
return Dist. support (d)[_rand (rng, p_cumulative, R)]
263
267
end
268
+ Base. rand (d:: UnivariateFinite ) = rand (Random. default_rng (), d)
264
269
265
270
function Base. rand (rng:: AbstractRNG ,
266
271
d:: UnivariateFinite{<:Any,<:Any,R} ,
267
- dim1:: Int , moredims:: Int ... ) where R # ref type
272
+ dim1:: Integer , moredims:: Integer ... ) where R # ref type
268
273
p_cumulative = _cumulative (d)
269
274
A = Array {R} (undef, dim1, moredims... )
270
275
for i in eachindex (A)
@@ -274,7 +279,8 @@ function Base.rand(rng::AbstractRNG,
274
279
return broadcast (i -> support[i], A)
275
280
end
276
281
277
- rng (d:: UnivariateFinite , args... ) = rng (Random. GLOBAL_RNG, d, args... )
282
+ Base. rand (d:: UnivariateFinite , dim1:: Integer , moredims:: Integer... ) =
283
+ rand (Random. default_rng (), d, dim1, moredims... )
278
284
279
285
function Dist. fit (d:: Type{<:UnivariateFinite} ,
280
286
v:: AbstractVector{C} ) where C
0 commit comments