The discrete uniform distribution can be easily obtained with the basic functions. I guess something on the lines of this should do: a <- round(runif(1000, min=0, max=100)) EDIT. As csgillespie pointed out, this is not correct... a <- ceiling(runif(1000, min=0, max=100)), 4/17/2020 · rdunif: Generate random sample from a discrete uniform distribution reduce: Reduce a list to a single value by iteratively applying a... reduce_right: Reduce from the right (retired) reexports: Objects exported from other packages rep_along: Repeat a value with matching length rerun: Re-run expressions multiple times. safely: Capture side effects.The R software provides access to the uniform distribution by the dunif(), punif(), qunif() and runif () functions. Apply the help() function on these functions for further information. The runif () function generates random deviates of the uniform distribution and is written as runif (n, min = 0, max = 1) .UNIFORM distribution in R [dunif, punif, qunif and runif ...R: generate uniform randum numbers with runif( ), R: generate uniform randum numbers with runif( ), Are there default functions for discrete uniform distributions in R? - Cro , R: generate uniform randum numbers with runif ( ) runif can be used to produce random numbers runif does not stand for run if. runif (n) generates n uniform random numbers between 0 and 1. runif (n, a, b) generates n uniform random numbers between a and b. In order to create the same random numbers, set.seed ( ) can be used.U= runif (nmin= 0max= 1) X= sum(U Discrete Distributions In general, we can generate any discrete random variables similar to the above examples using the following algorithm. Suppose we would like to simulate the discrete random variable Xwith range R X = fx 1x 2:::x ngand P(X= x j) = p j, so P j p j= 1.cdf = cumsum( runif (10000, 0, 0.1)) cdf = cdf/max(cdf) Next generate N uniform random numbers: N = 1000 u = runif (N) Now sample the value: ##With some experimenting this seemed to be very quick ##However, with N = 100000 we run out of memory ##N = 10^6 would be a reasonable maximum to cope with colSums(sapply(u, >, cdf)), rdunif. : Generate random sample from a discrete uniform distribution.
The main differences are in the defaults and if you don’t change those defaults then both would give something called a uniform (though sample would be considered a discrete uniform and by default without replacement). Edit. The more correct comparison is: > ceiling( runif (10,0,100)) [1] 27 38 58 91 21 90 95 67 63 7 instead of using round.