Skip to content

Commit

Permalink
Merge pull request #311 from tlnagy/tn/global-rng-fix
Browse files Browse the repository at this point in the history
use local rng for uuid generation, fixes #198
  • Loading branch information
tlnagy committed Oct 1, 2018
2 parents 69b4d95 + f85d605 commit d6ac6f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/svg.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Base64
using UUIDs
using Random

const snapsvgjs = joinpath(dirname(@__FILE__), "..", "data", "snap.svg-min.js")

Expand Down Expand Up @@ -138,6 +139,8 @@ end

SVGPropertyFrame() = SVGPropertyFrame(Dict{Type, Property}(), false, false, false, false)

const LOCAL_RNG = MersenneTwister()

mutable struct SVG <: Backend
# Image size in millimeters.
width::AbsoluteLength
Expand Down Expand Up @@ -224,7 +227,7 @@ function SVG(out::IO,
jsmode::Symbol=:none;

cached_out = nothing,
id = string("img-", string(uuid4())[1:8]),
id = string("img-", string(uuid4(LOCAL_RNG))[1:8]),
indentation = 0,
property_stack = Array{SVGPropertyFrame}(undef, 0),
vector_properties = Dict{Type, Union{Property, Nothing}}(),
Expand Down
9 changes: 9 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,12 @@ end
@testset "Image keyword args" begin
@test typeof(PNG("foo.png", 4inch, 3inch, dpi=172)) <: Compose.Image
end

@testset "No Global RNG contamination" begin
Random.seed!(23)
withoutcompose = rand()
Random.seed!(23)
draw(SVG(), compose(context()))
withcompose = rand()
@test withoutcompose == withcompose
end

0 comments on commit d6ac6f8

Please sign in to comment.