Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only maintain internal widget ID seed if the user has called setWidgetIdSeed() #423

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions R/widgetid.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,26 @@ createWidgetId <- function(bytes = 10) {

# Note what the system's random seed is before we start, so we can restore it after
sysSeed <- .GlobalEnv$.Random.seed
# Replace system seed with our own seed

if (!is.null(.globals$idSeed)) {
# Replace system seed with our own seed
.GlobalEnv$.Random.seed <- .globals$idSeed
on.exit({
# Continue using our own seed for subsequent widget ids
.globals$idSeed <- .GlobalEnv$.Random.seed
})
} else if (exists(".Random.seed", envir = .GlobalEnv)) {
# or remove the seed for a fresh RNG if we don't have an internal RNG state
rm(".Random.seed", envir = .GlobalEnv)
}

on.exit({
# Change our own seed to match the current seed
.globals$idSeed <- .GlobalEnv$.Random.seed
# Restore the system seed--we were never here
if(!is.null(sysSeed))
if (!is.null(sysSeed))
.GlobalEnv$.Random.seed <- sysSeed
else
rm(".Random.seed", envir = .GlobalEnv)
})
}, add = TRUE)

paste(
format(as.hexmode(sample(256, bytes, replace = TRUE)-1), width=2),
Expand Down