Overview

  1. Use a random generator that generates uniform random numbers on the interval [0,1] to write a computer program that generates discrete random numbers \(\xi\)=1,2,3,4,5,6.
  2. Compute the cumulative probability density \(P(x)\) with a sequence of 1000 random numbers \(\xi\).
  3. Compute the probability density \({\rho}_{\xi}(x)\) with a sequence of 1000 random numbers \(\xi\).

Function: dice(side)

dice<-function(side){
     x <- runif(n = 1,min = 0.,max = 1.)
     x <- x*side + 1
     as.integer(x)
}

This function takes input as the number of sides of the dice, and gives out put as the integer number as the rolled dice. Dice is uniformly distributed.

We write the script that rolls a \(\xi =\) 6-side dice for \(10^{4}\) times.

CDF: \(P(x)\)

plot(ecdf(roll))

PDF: \({\rho}_{\xi}(x)\)

hist(x = roll, freq = 0, right = 1, breaks =c(0:6))