Custom Sampler with multiple parameters

I would probably do something like this

using Random

Random.rand(T::Type, b::B, k) = Random.rand(Random.default_rng(), T, b, k)

function Random.rand(rng::AbstractRNG, T::Type, b::B, k)
	# random operations
	a = rand(rng) * b.x + k
	T(a, k)
end

Modify the code inside the function as you wish, e.g. to get your vector.

Then

julia> rand(A, B(3), 5) # uses default random generator
A(5.48452407660821, 5.0)

julia> rand(A, B(3), 5)
A(5.93748059591882, 5.0)

julia> rand(MersenneTwister(0), A, B(3), 5) # custom
A(7.470942523932237, 5.0)

julia> rand(MersenneTwister(0), A, B(3), 5)  # same result
A(7.470942523932237, 5.0)

1 Like