uniform: Generate random numbers

Description Usage Arguments Details Value References See Also Examples

Description

.lec.uniform generates U(0,1) random numbers.

.lec.uniform.int generates random numbers from the discrete uniform distribution over integers.

Usage

1
2
3
.lec.uniform (name, n = 1)

.lec.uniform.int (name, n = 1, a = 0, b = 10)

Arguments

name

name of the stream.

n

number of random numbers to be generated.

a,b

interval from which the integer random numbers should be generated.

Details

.lec.uniform and .lec.uniform.int, respectively, are wrapper functions for the C functions RngStream_RandU01 and RngStream_RandInt, respectively (L'Ecuyer et al, 2002).

Note: Since the stream is here identified by name, there is no need for using the CurrentStream pair.

Value

A vector of n random numbers.

References

P. L'Ecuyer, R. Simard, E.J.Chen and W.D.Kelton: An Object-Oriented Random-Number Package With Many Long Streams and Substreams; Operations Research, vol. 50, nr. 6, 2002.

See Also

.lec.CurrentStream

Examples

1
2
3
4
5
6
7
8
nstreams <- 10       # number of streams
seed<-rep(1,6)
.lec.SetPackageSeed(seed)
names <- paste("mystream",1:nstreams,sep="")
.lec.CreateStream(names)
for (i in 1:nstreams)   # generate 10 RNs from each stream
      print(.lec.uniform(names[i],10))
.lec.DeleteStream(names)

Example output

[1] 1 1 1 1 1 1
 [1] 0.0003395772 0.5558807160 0.0142046607 0.0881226713 0.4411733820
 [6] 0.7991554535 0.3129617716 0.8164760514 0.2346017519 0.6388651433
 [1] 0.16644823 0.82381720 0.75445447 0.53854099 0.26967246 0.06088786
 [7] 0.81342873 0.45647629 0.27758519 0.01979045
 [1] 0.40953779 0.19805827 0.86853361 0.56841918 0.64657563 0.90668672
 [7] 0.15669687 0.06503323 0.10323087 0.33794767
 [1] 0.1473558 0.8921580 0.8659602 0.1710683 0.5729402 0.2041932 0.7582495
 [8] 0.5783814 0.1698808 0.4933208
 [1] 0.9170475 0.7046074 0.8707009 0.3082317 0.9336580 0.7457962 0.4804126
 [8] 0.2772204 0.9140097 0.2832278
 [1] 0.634454068 0.852744999 0.006132466 0.735465643 0.542085787 0.055688283
 [7] 0.626208875 0.656744698 0.478900680 0.920568701
 [1] 0.37367351 0.08135017 0.27044390 0.42420094 0.18843716 0.20690125
 [7] 0.30373641 0.03298780 0.60379127 0.14428779
 [1] 0.069244756 0.001837285 0.030587501 0.622354055 0.049580785 0.545481241
 [7] 0.286665477 0.829309228 0.706257205 0.212599694
 [1] 0.3227408 0.7074169 0.8153675 0.3631263 0.2484977 0.5835658 0.5306508
 [8] 0.1169660 0.4276150 0.6320671
 [1] 0.3237190 0.3253448 0.1864128 0.1318845 0.4550973 0.3438756 0.5303345
 [8] 0.6139807 0.5200416 0.7731785

rlecuyer documentation built on May 29, 2017, 2:50 p.m.