ds.rUnif {dsBaseClient} | R Documentation |

Generates random (pseudorandom) numbers with a uniform distribution

ds.rUnif(samp.size = 1, min = 0, max = 1, newobj = "newObject", seed.as.integer = NULL, return.full.seed.as.set = FALSE, force.output.to.k.decimal.places = 9, datasources = NULL)

`samp.size` |
the length of the random number vector to be created in each source. <samp.size> can be a numeric scalar and this then specifies the length of the random vectors in each source to be the same. If it is a numeric vector it enables the random vectors to be of different lengths in each source but the numeric vector must be of length equal to the number of data sources being used. Often, one wishes to generate random vectors of length equal to the length of standard vectors in each source. To do this most easily, issue a command such as: numobs.list<-ds.length('varname',type='split') where varname is an arbitrary vector of standard length in all sources. Then issue command: numobs<-unlist(numobs.list) to make numobs numeric rather than a list. Finally, declare samp.size=numobs as the first argument for the ds.rUnif function Please note that because (in this case) numobs is a clientside vector it should be specified without inverted commas (unlike the serverside vectors which may be used for the <min> and <max> arguments [see below]). |

`min` |
a numeric scalar specifying the minimum of the range across which the random numbers will be generated in each source. Alternatively you can specify the <min> argument to be a serverside vector equal in length to the random number vector you want to generate. This allows min to vary by observation in the dataset. If you wish to specify a serverside vector in this way (e.g. called vector.of.mins) you must specify the argument as a character string (..., min="vector.of.mins"...). If you simply wish to specify a single but different value in each source, then you can specify <min> as a scalar and use the <datasources> argument to create the random vectors one source at a time. Default value for <min> = 0. |

`max` |
a numeric scalar specifying the maximum of the range across which the random numbers will be generated in each source. Alternatively you can specify the <max> argument to be a serverside vector equal in length to the random number vector you want to generate. This allows max to vary by observation in the dataset. If you wish to specify a serverside vector in this way (e.g. called vector.of.maxs) you must specify the argument as a character string (..., max="vector.of.maxs"...). If you simply wish to specify a single but different value in each source, then you can specify <max> as a scalar and use the <datasources> argument to create the random vectors one source at a time. Default value for <max> = 1 |

`newobj` |
This a character string providing a name for the output random number vector which defaults to 'newObject' if no name is specified. |

`seed.as.integer` |
a numeric scalar or a NULL which primes the random seed in each data source. If <seed.as.integer> is a numeric scalar (e.g. 938) the seed in each study is set as 938*1 in the first study in the set of data sources being used, 938*2 in the second, up to 938*N in the Nth study. If <seed.as.integer> is set as 0 all sources will start with the seed value 0 and all the random number generators will therefore start from the same position. If you want to use the same starting seed in all studies but do not wish it to be 0, you can specify a non-zero scalar value for <seed.as.integer> and then use the <datasources> argument to generate the random number vectors one source at a time (e.g. ,datasources=default.opals[2] to generate the random vector in source 2). As an example, if the <seed.as.integer> value is 78326 then the seed in each source will be set at 78326*1 = 78326 because the vector of datasources being used in each call to the function will always be of length 1 and so the source-specific seed multiplier will also be 1. The function ds.rUnif calls the serverside assign function setSeedDS to create the random seeds in each source |

`return.full.seed.as.set` |
logical, if TRUE will return the full random number seed in each data source (a numeric vector of length 626). If FALSE it will only return the trigger seed value you have provided: eg if <seed.as.integer> = 32 and there are three studies, the ds.rUnif function will return: "$integer.seed.as.set.by.source", [1] 32 64 96, rather than the three vectors each of length 626 that represent the full seeds generated in each source. Default is FALSE. |

`force.output.to.k.decimal.places` |
scalar integer. Forces the output random number vector to have k decimal places. If 0 rounds it coerces decimal random number output to integer, a k in range 1-8 forces output to have k decimal places. If k = 9, no rounding occurs of native output. NOTE IF YOU WANT CATEGORIES WITH EQUAL PROBABILITY (PARTICULARLY WHEN CREATING INTEGERS) YOU SHOULD EXTEND THE SIMULATION RANGE AT BOTH ENDS: IF K = 0 AND YOU WISH TO GENERATE INTEGERS WITH EQUAL PROBABILITY IN THE RANGE 1-10, YOU SHOULD SPECIFY <min>=0.5 AND <max>=10.5. Default value for k =9. |

`datasources` |
specifies the particular opal object(s) to use. If the <datasources> argument is not specified the default set of opals will be used. The default opals are called default.opals and the default can be set using the function ds.setDefaultOpals. If the <datasources> is to be specified, it should be set without inverted commas: e.g. datasources=opals.em or datasources=default.opals. If you wish to apply the function solely to e.g. the second opal server in a set of three, the argument can be specified as: e.g. datasources=opals.em[2]. If you wish to specify the first and third opal servers in a set you specify: e.g. datasources=opals.em[c(1,3)] |

An assign function that creates a vector of pseudorandom numbers in each data source. This function generates random numbers distributed with a uniform probability across a range specified with a minimum and maximum. The function's arguments specify the length of the output vector in each source and the minimum and maximum of the range across which the uniform distribution to be generated.

Writes the pseudorandom number vector with the characteristics specified in the function call as a new serverside vector in each data source. Also returns key information to the clientside: the random seed trigger as specified by you in each source + (if requested) the full 626 length random seed vector this generated in each source (see info for the argument <return.full.seed.as.set>). The ds.rUnif function also returns a vector reporting the length of the pseudorandom vector created in each source.

Paul Burton for DataSHIELD Development Team

[Package *dsBaseClient* version 5.0.0 ]