ds.setSeed {dsBaseClient}R Documentation

Server-side random number generation


Primes the pseudorandom number generator in a data source


ds.setSeed(seed.as.integer = NULL, datasources = NULL)



a numeric value or a NULL that primes the random seed in each data source.


a list of DSConnection-class objects obtained after login. If the datasources argument is not specified the default set of connections will be used: see datashield.connections_default.


This function generates an instance of the full pseudorandom number seed that is a vector of integers of length 626 called .Random.seed, this vector is written to the server-side.

This function is similar to a native R function set.seed().

In seed.as.integer argument the current limitation on the value of the integer that can be specified is -2147483647 up to +2147483647 (this is +/- ([2^31]-1)).

Because you only specify one integer in the call to ds.setSeed (i.e. the value for the seed.as.integer argument) that value will be used as the priming trigger value in all of the specified data sources and so the pseudorandom number generators will all start from the same position and if a vector of pseudorandom number values is requested based on one of DataSHIELD's pseudorandom number generating functions precisely the same random vector will be generated in each source. If you want to avoid this you can specify a different priming value in each source by using the datasources argument to generate the random number vectors one source at a time with a different integer in each case.

Furthermore, if you use any one of DataSHIELD's pseudorandom number generating functions: ds.rNorm, ds.rUnif, ds.rPois or ds.rBinom. The function call itself automatically uses the single integer priming seed you specify to generate different integers in each source.

Server function called: setSeedDS


Sets the values of the vector of integers of length 626 known as .Random.seed on each data source that is the true current state of the random seed in each source. It also returns the value of the trigger integer that has primed the random seed vector (.Random.seed) in each source and also the integer vector of 626 elements that is .Random.seed itself.


DataSHIELD Development Team


## Not run: 
  ## Version 6, for version 5 see the Wiki 
  # Connecting to the Opal servers


  builder <- DSI::newDSLoginBuilder()
  builder$append(server = "study1", 
                 url = "", 
                 user = "administrator", password = "datashield_test&", 
                 table = "CNSIM.CNSIM1", driver = "OpalDriver")
  builder$append(server = "study2", 
                 url = "", 
                 user = "administrator", password = "datashield_test&", 
                 table = "CNSIM.CNSIM2", driver = "OpalDriver")
  builder$append(server = "study3",
                 url = "", 
                 user = "administrator", password = "datashield_test&", 
                 table = "CNSIM.CNSIM3", driver = "OpalDriver")
  logindata <- builder$build()

  # Log onto the remote Opal training servers
  connections <- DSI::datashield.login(logins = logindata, assign = TRUE, symbol = "D") 
  #Generate a pseudorandom number in the server-side
  ds.setSeed(seed.as.integer = 152584,
             datasources = connections)
  #Specify the pseudorandom number only in the first source
  ds.setSeed(seed.as.integer = 741,
             datasources = connections[1])#only the frist study is used (study1)
  # Clear the Datashield R sessions and logout  
## End(Not run)

[Package dsBaseClient version 6.3.0 ]