3.5.5.10 UniformUniform-func
Description
This function returns a range with npts number of values. The initial starting value in the range is determined by seed.
The seed can be a value, a data range (e.g. a column), or strings (with "|" or "," or spaces as separators), or a string array. Note that a vector can substitute for the seed.
Note: The seeding algorithm for Origin's methods of random number generation was changed for version 2016. For more information, see documentation for the system variable @ran.
|
Syntax
//When seed is a value
dataset uniform(int npts[, int seed])
//When seed is strings
dataset uniform(int npts, string seed)
//When seed is a data range
dataset uniform(int npts, dataset seed)
Parameter
npts
- the number of values in the returned dataset.
seed or vd
- can be a value, a data range (e.g. a column), strings (with "|" or "," or spaces as separators), or a string array. It is used to initialize the returned pseudorandom dataset. According to the different types of seed, we have
- If seed is a value, generated values are random numbers with uniform (between 0 and 1) distribution. If seed is omitted, a different seed is used each time the function is called.
- If seed is a data range or string array (e.g. a column), the generated values will be randomly chosen from the data range or string(s).
- A vector vd can be used in place of seed, in which case, the generated values will be randomly chosen from vd.
Return
Returns a range with npts number of values.
Examples
This example shows use of a value as the seed:
col(A) = uniform(5);//Fill in the first 5 cells in column A with uniformly distributed data.
This example shows use of a data range(column) as seed:
col(B) = uniform(30, col(A));//Randomly choose 30 elements from col(A) to fill col(B)
This example shows use of a string array as seed:
//Create stringarray stra with strings "Origin" and "Lab"
stringarray stra;
stra.Add("Origin");
stra.Add("Lab");
//Use the stra as seed
col(C) = uniform(10, stra);
This example shows how to use a string as seed (three kinds of separators are supported):
col(D) = uniform(10, "Origin|Lab");
col(E) = uniform(10, "Origin,Lab");
col(F) = uniform(10, "Origin Lab");
|