# Monte Carlo Simulations

All theoretical results from the application of the inequalities have been confirmed by Monte Carlo simulations, each of which involved 10 million trials. For fractions of high reliability components of 0.9, 0.55 and 0.35, characterising the three suppliers, the Monte Carlo simulation resulted in probabilities *p* =0.41 and *p _{2}* =0.33 of purchasing two high-reliability components from a randomly selected single supplier and from two randomly selected suppliers, correspondingly. The left and right parts of inequality (6.1) give

*p*= 0.41 and

*p*= 0.33 for the same probabilities, which confirms the validity of inequality (6.1).

_{2}The simulation of purchasing two components from a randomly selected supplier and testing the components for high reliability has been done within a loop of ten million trials. The pseudo-code fragment related to evaluating the empirical probability of purchasing tw'o high-reliability components from a single supplier is shown next.

**Algorithm 6.1**

a= [0.9, 0.55, 0.35]

П=3; num_trials=10000000; count1=0;

for i=l to num_trials do

**{**

sup_no=[n*rand()]+1; x=rand(); y=rand();

if(x<=a[sup_no] and y<=a[sup_no]) then countl=countl+l;

**}**

probability_l=countl/num_trials;

A supplier is selected randomly with the statement sup_no= [n*rand() ] +1; where [n*rand () ] is the greatest integer part that does not exceed n* rand () and rand () is a function that returns a random number uniformly distributed in the interval (0,1)- The fractions of high-reliability components, characterising the suppliers are specified in the array a[]. In the test case, a[0.9,0.55,0.35] has been specified for the three suppliers. The test for two high-reliability components is performed by the conditional statement

**if**(x<=a[sup_no] **and **y<=a[sup_no]) **then **countl =countl+l;

where *x* and *у* are two uniformly distributed random numbers in the interval (0,1). If the compound condition x<=a[sup_no] and y<=a[sup_no] is true, this means that both components are high-reliability components, in which case, the counter countl is incremented. The counter countl tracks the number of instances where two high-reliability components have been selected. If the compound condition is false, the counter countl is not incremented.

Finally, the probability of purchasing two high-reliability components from a randomly selected single supplier is obtained by dividing the content of the counter to the number of trials.

Simulating purchasing of two high-reliability components from two randomly selected suppliers is done in a similar fashion. The algorithm in pseudo-code is given next.

Algorithm 6.2

a= [0.9, 0.55, 0.35]

П=3; num_trials=10000000; count2=0;

**for **i=l **to **num_trials **do**

**{**

f_sup_no=[n*rand() ] +1; **switch **(f_sup_no)

**{**

**case **1: q=rand();

**if **(q<=0.5) **then **s_sup_no=3; **else **s_SUp_no=2;

**case **2: q=rand**();**

**if **(q<=0.5) **then **s_sup_no=l; **else **s_SUp_no=3;

**case **3: q=rand**();**

**if **(q<=0.5) **then **s_sup_no=2; **else **s_sup_no=l;

**}**

x=rand(); y=rand();

**if**(xand ythen count2=count2+l;

**}**

probability_2=count2/num_trials;

Initially, a first supplier is randomly selected, with the statement f_sup_no= [n*rand () ] +1;.

Next, from the remaining two suppliers, one more supplier is randomly selected by using the random variable *q* to which the function rand() assigns value which is uniformly distributed over the interval (0,1). Depending on whether *q* is smaller or greater than 0.5 one of the remaining two suppliers is selected. The index of the randomly selected second supplier is kept in the variable s_sup_no. High-reliability components from the two randomly selected suppliers are ‘purchased’ by generating two random numbers in the interval (0,1) with the statements: x=rand(); y=rand(). If both *x* and *у* are smaller than the corresponding probabilities for a high-reliability component, the purchased components are high-reliability components and the counter count2 is incremented in the conditional statement

if(x

Finally, the probability of purchasing two high-reliability components from two randomly selected suppliers is obtained by dividing the content of the counter count2 by the number of simulation trials: probability_2 = count2/ num_trials;.

The two simulation loops for purchasing components from a single random supplier and two random suppliers can be combined into a single simulation loop.

Suppose that three available suppliers are again characterised by the fractions x, =0.9, *x _{2}* =0.55 and x

_{3}=0.35 of high-reliability components. The Monte Carlo simulation based on 10 million trials resulted in probabilities

*p*=0.313and

*p*=0.17 of purchasing three high reliability components from a randomly selected single supplier and from all three available suppliers, correspondingly. The left and right parts of inequality (6.3) give

_{2}*p*=0.313 and

_{t}*p*=0.17 for the same probabilities, which confirms the validity of inequality (6.3).

_{2}In the case of purchasing three high-reliability components from a randomly selected single supplier and from two randomly selected suppliers, the Monte Carlo simulation based on 10 million trials resulted in probabilities *p* =0.313 and *p _{2}* = 0.214, respectively.

The left and right sides of inequality (6.4) give *p* =0.313 and *p _{2}* =0.214 for the same probabilities, which confirms the validity of Inequality (6.4).

Suppose that the fractions of high-reliability components characterising the three suppliers are x, =0.9, x_{2} = 0.75 and x_{3} =0.25. The Monte Carlo simulation based on 10 million trials resulted in probabilities *p* = 0.389 and *p _{2}* = 0.26 of purchasing three high reliability components from a randomly selected single supplier and from two randomly selected suppliers, correspondingly. The left and right parts of inequality (6.4) yield again the same probabilities of

*p*= 0.389 and

*p*= 0.26 which confirms the validity of inequality (6.4).

_{2}The Monte Carlo simulation algorithms relevant to purchasing three components are very similar to the simulation algorithm described earlier and to conserve space, details have been omitted.